Compare commits
2 Commits
cae7fecb51
...
1208f1f59f
Author | SHA1 | Date | |
---|---|---|---|
1208f1f59f | |||
93a0b6cf58 |
@ -35,6 +35,10 @@ concept nullable_type = !std::is_same_v<T, std::nullptr_t> && requires(T t) { t
|
||||
template<nullable_type T>
|
||||
class NotNullable
|
||||
{
|
||||
public:
|
||||
using wrapped_t = T;
|
||||
using element_type = std::remove_reference_t<decltype(*std::declval<const wrapped_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<typename TOther> requires(std::is_base_of_v<typename NotNullable<TOther>::element_type, element_type> && std::is_constructible_v<T, pointer>)
|
||||
explicit constexpr NotNullable(const NotNullable<TOther>& other) MIJIN_NOEXCEPT_IF((std::is_nothrow_constructible_v<T, pointer>))
|
||||
: base_(static_cast<pointer>(&*other))
|
||||
{
|
||||
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))
|
||||
|
@ -4,6 +4,7 @@
|
||||
#if !defined(MIJIN_UTIL_VARIANT_HPP_INCLUDED)
|
||||
#define MIJIN_UTIL_VARIANT_HPP_INCLUDED 1
|
||||
|
||||
#include <utility>
|
||||
#include <variant>
|
||||
#include "./traits.hpp"
|
||||
|
||||
@ -23,10 +24,21 @@ inline constexpr bool variant_contains_v<TSearch, std::variant<TVariantTypes...>
|
||||
//
|
||||
// public types
|
||||
//
|
||||
|
||||
template<typename... TCallable>
|
||||
struct Visitor : TCallable ...
|
||||
{
|
||||
using TCallable::operator()...;
|
||||
};
|
||||
|
||||
template<typename TRet>
|
||||
struct CastTo
|
||||
{
|
||||
template<typename T>
|
||||
TRet operator()(T&& arg) const
|
||||
{
|
||||
return static_cast<TRet>(std::forward<T>(arg));
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif // !defined(MIJIN_UTIL_VARIANT_HPP_INCLUDED)
|
||||
|
Loading…
x
Reference in New Issue
Block a user