From 042e0d2465f8173a2cc61c474c16c8c26ef20d7f Mon Sep 17 00:00:00 2001 From: Patrick Wuttke Date: Sat, 12 Jul 2025 12:49:45 +0200 Subject: [PATCH] Added explicit constructor for casting between related not-nullable pointers. --- source/mijin/util/annot.hpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/source/mijin/util/annot.hpp b/source/mijin/util/annot.hpp index d1dd3e9..6ee18e4 100644 --- a/source/mijin/util/annot.hpp +++ b/source/mijin/util/annot.hpp @@ -35,6 +35,10 @@ concept nullable_type = !std::is_same_v && requires(T t) { t template class NotNullable { +public: + using wrapped_t = T; + using element_type = std::remove_reference_t())>; + using pointer = element_type*; private: T base_; public: @@ -55,6 +59,12 @@ public: { MIJIN_ASSERT(base_ != nullptr, "Constructed non-nullable type with nullptr."); } + template requires(std::is_base_of_v::element_type, element_type> && std::is_constructible_v) + explicit constexpr NotNullable(const NotNullable& other) MIJIN_NOEXCEPT_IF((std::is_nothrow_constructible_v)) + : base_(static_cast(&*other)) + { + 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))