Added converting constructors for NotNullable.
This commit is contained in:
parent
05bc3d5147
commit
9c4765dbaf
@ -29,7 +29,10 @@
|
||||
|
||||
namespace mijin
|
||||
{
|
||||
template<typename T> requires(!std::is_same_v<T, std::nullptr_t>) && requires(T t) { t == nullptr; }
|
||||
template<typename T>
|
||||
concept nullable_type = !std::is_same_v<T, std::nullptr_t> && requires(T t) { t == nullptr; };
|
||||
|
||||
template<nullable_type T>
|
||||
class NotNullable
|
||||
{
|
||||
private:
|
||||
@ -41,6 +44,18 @@ public:
|
||||
{
|
||||
MIJIN_ASSERT(base_ != nullptr, "Constructed non-nullable type with nullptr.");
|
||||
}
|
||||
template<typename TOther> requires(std::is_constructible_v<T, const TOther&>)
|
||||
constexpr NotNullable(const NotNullable<TOther>& other) MIJIN_NOEXCEPT_IF((std::is_nothrow_constructible_v<T, const TOther&>))
|
||||
: base_(other.base_)
|
||||
{
|
||||
MIJIN_ASSERT(base_ != nullptr, "Constructed non-nullable type with nullptr.");
|
||||
}
|
||||
template<typename TOther> requires(std::is_constructible_v<T, TOther&&>)
|
||||
constexpr NotNullable(NotNullable<TOther>&& other) MIJIN_NOEXCEPT_IF((std::is_nothrow_constructible_v<T, TOther&&>))
|
||||
: base_(std::exchange(other.base_, nullptr))
|
||||
{
|
||||
MIJIN_ASSERT(base_ != nullptr, "Constructed non-nullable type with nullptr.");
|
||||
}
|
||||
template<typename TArg, typename... TArgs> requires(!std::is_same_v<TArg, std::nullptr_t>
|
||||
&& (!std::is_same_v<TArg, T> && sizeof...(TArgs) == 0)
|
||||
&& std::is_constructible_v<T, TArg&&, TArgs&&...>)
|
||||
@ -129,6 +144,9 @@ public:
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr const T& get() const MIJIN_NOEXCEPT { return base_; }
|
||||
|
||||
template<nullable_type TOther>
|
||||
friend class NotNullable;
|
||||
};
|
||||
|
||||
#if MIJIN_USE_GSL
|
||||
|
Loading…
x
Reference in New Issue
Block a user