aboutsummaryrefslogtreecommitdiff
path: root/src/unique.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/unique.hpp')
-rw-r--r--src/unique.hpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/unique.hpp b/src/unique.hpp
index 98a9d48..27ea71e 100644
--- a/src/unique.hpp
+++ b/src/unique.hpp
@@ -10,6 +10,7 @@ class Unique
10 T val; // no default initialization so that std::is_trivial_v<Unique<T>> == true 10 T val; // no default initialization so that std::is_trivial_v<Unique<T>> == true
11 11
12 public: 12 public:
13 using self = Unique<T, TAG, specialization>;
13 using type = T; 14 using type = T;
14 15
15 ~Unique() = default; 16 ~Unique() = default;
@@ -25,12 +26,20 @@ class Unique
25 constexpr Unique& operator=(Unique const&) = default; 26 constexpr Unique& operator=(Unique const&) = default;
26 constexpr Unique& operator=(Unique&&) = default; 27 constexpr Unique& operator=(Unique&&) = default;
27 28
29 // Forbid construction with any other class, especially with types that convert naturally to UnderlyingType.
30 // For instance, this prevents construction with a float when UnderlyingType is an integer type.
31 // Conversion will have to be explicit and the developer will be aware of it.
32 // However we want to keep the same-type copy constructors (including with an inherited class), hence the enable_if stuff.
33 template <typename AnyOtherClass, std::enable_if_t<!std::is_base_of_v<self, std::decay_t<AnyOtherClass>>, bool> = true>
34 Unique(AnyOtherClass&&) = delete;
35
28 // can't implicitly affect from base type 36 // can't implicitly affect from base type
29 Unique& operator=(T const&) = delete; 37 Unique& operator=(T const&) = delete;
30 constexpr Unique& operator=(T&&) = delete; 38 constexpr Unique& operator=(T&&) = delete;
31 39
32 // cast 40 // cast
33 constexpr operator T() const noexcept { return val; } 41 constexpr operator T() const noexcept { return val; }
42 constexpr T value() const noexcept { return val; }
34 43
35 // pre-increment 44 // pre-increment
36 auto& operator++() noexcept 45 auto& operator++() noexcept