diff --git a/source/mijin/util/annot.hpp b/source/mijin/util/annot.hpp index 822a53e..c6061df 100644 --- a/source/mijin/util/annot.hpp +++ b/source/mijin/util/annot.hpp @@ -29,7 +29,10 @@ namespace mijin { -template requires(!std::is_same_v) && requires(T t) { t == nullptr; } +template +concept nullable_type = !std::is_same_v && requires(T t) { t == nullptr; }; + +template class NotNullable { private: @@ -41,6 +44,18 @@ public: { MIJIN_ASSERT(base_ != nullptr, "Constructed non-nullable type with nullptr."); } + template requires(std::is_constructible_v) + constexpr NotNullable(const NotNullable& other) MIJIN_NOEXCEPT_IF((std::is_nothrow_constructible_v)) + : base_(other.base_) + { + MIJIN_ASSERT(base_ != nullptr, "Constructed non-nullable type with nullptr."); + } + template requires(std::is_constructible_v) + constexpr NotNullable(NotNullable&& other) MIJIN_NOEXCEPT_IF((std::is_nothrow_constructible_v)) + : base_(std::exchange(other.base_, nullptr)) + { + MIJIN_ASSERT(base_ != nullptr, "Constructed non-nullable type with nullptr."); + } template requires(!std::is_same_v && (!std::is_same_v && sizeof...(TArgs) == 0) && std::is_constructible_v) @@ -129,6 +144,9 @@ public: [[nodiscard]] constexpr const T& get() const MIJIN_NOEXCEPT { return base_; } + + template + friend class NotNullable; }; #if MIJIN_USE_GSL