Remove convertible_from
This commit is contained in:
@ -87,14 +87,11 @@ template<typename T> concept trivially_destructible = __is_trivially_destructibl
|
|||||||
template<typename T> concept copyable = copy_constructible<T> && copy_assignable<T>;
|
template<typename T> concept copyable = copy_constructible<T> && copy_assignable<T>;
|
||||||
template<typename T> concept moveable = move_constructible<T> && move_assignable<T>;
|
template<typename T> concept moveable = move_constructible<T> && move_assignable<T>;
|
||||||
|
|
||||||
template<typename To, typename From>
|
|
||||||
concept convertible_from = __is_convertible(From, To);
|
|
||||||
|
|
||||||
template<typename From, typename To>
|
template<typename From, typename To>
|
||||||
concept convertible_to = __is_convertible(From, To);
|
concept convertible_to = __is_convertible(From, To);
|
||||||
|
|
||||||
template<typename Derived, class Base>
|
template<typename Derived, class Base>
|
||||||
concept derived_from = __is_class(Derived) && __is_class(Base) && convertible_from<const volatile Base*, const volatile Derived*>;
|
concept derived_from = __is_class(Derived) && __is_class(Base) && convertible_to<const volatile Derived*, const volatile Base*>;
|
||||||
|
|
||||||
using nullptr_t = decltype(nullptr);
|
using nullptr_t = decltype(nullptr);
|
||||||
|
|
||||||
@ -258,7 +255,7 @@ concept derefs_as = is_object<To> &&
|
|||||||
(convertible_to<un_ref_t<From>&, To&> || _dereferenceable_as_convertible<un_ref_t<From>, To>);
|
(convertible_to<un_ref_t<From>&, To&> || _dereferenceable_as_convertible<un_ref_t<From>, To>);
|
||||||
|
|
||||||
template<typename To, derefs_as<To> From>
|
template<typename To, derefs_as<To> From>
|
||||||
constexpr auto&& deref(From&& from) // NOLINT(*forward*)
|
constexpr auto&& deref(From&& from) // NOLINT(*-missing-std-forward)
|
||||||
{
|
{
|
||||||
if constexpr (_dereferenceable_as_convertible<From, To>)
|
if constexpr (_dereferenceable_as_convertible<From, To>)
|
||||||
{
|
{
|
||||||
|
@ -205,19 +205,19 @@ class C {};
|
|||||||
class D { public: operator C() { return c; } C c; }; // NOLINT
|
class D { public: operator C() { return c; } C c; }; // NOLINT
|
||||||
class E { public: template<class T> E(T&&) {} }; // NOLINT
|
class E { public: template<class T> E(T&&) {} }; // NOLINT
|
||||||
|
|
||||||
static_assert(asl::convertible_from<Base*, Derived*>);
|
static_assert(asl::convertible_to<Derived*, Base*>);
|
||||||
static_assert(!asl::convertible_from<Derived*, Base*>);
|
static_assert(!asl::convertible_to<Base*, Derived*>);
|
||||||
static_assert(asl::convertible_from<C, D>);
|
static_assert(asl::convertible_to<D, C>);
|
||||||
static_assert(!asl::convertible_from<C*, Derived*>);
|
static_assert(!asl::convertible_to<Derived*, C*>);
|
||||||
static_assert(asl::convertible_from<E, Base>);
|
static_assert(asl::convertible_to<Base, E>);
|
||||||
|
|
||||||
static_assert(!asl::convertible_from<int16_t(&)[], int32_t(&)[]>);
|
static_assert(!asl::convertible_to<int32_t(&)[], int16_t(&)[]>);
|
||||||
static_assert(asl::convertible_from<const int16_t(&)[], int16_t(&)[]>);
|
static_assert(asl::convertible_to<int16_t(&)[], const int16_t(&)[]>);
|
||||||
static_assert(asl::convertible_from<const int16_t(&)[], const int16_t(&)[]>);
|
static_assert(asl::convertible_to<const int16_t(&)[], const int16_t(&)[]>);
|
||||||
static_assert(asl::convertible_from<int16_t(&)[], int16_t(&)[]>);
|
static_assert(asl::convertible_to<int16_t(&)[], int16_t(&)[]>);
|
||||||
static_assert(!asl::convertible_from<int32_t(&)[], int16_t(&)[]>);
|
static_assert(!asl::convertible_to<int16_t(&)[], int32_t(&)[]>);
|
||||||
static_assert(!asl::convertible_from<int16_t(&)[], const int16_t(&)[]>);
|
static_assert(!asl::convertible_to<const int16_t(&)[], int16_t(&)[]>);
|
||||||
static_assert(!asl::convertible_from<C(&)[], D(&)[]>);
|
static_assert(!asl::convertible_to<D(&)[], C(&)[]>);
|
||||||
|
|
||||||
static_assert(asl::derived_from<Derived, Base>);
|
static_assert(asl::derived_from<Derived, Base>);
|
||||||
static_assert(!asl::derived_from<Base, Derived>);
|
static_assert(!asl::derived_from<Base, Derived>);
|
||||||
|
@ -40,7 +40,7 @@ public:
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
template<is_object U>
|
template<is_object U>
|
||||||
requires convertible_from<T*, U*>
|
requires convertible_to<U*, T*>
|
||||||
constexpr box(box<U, Allocator>&& other) // NOLINT(*explicit*,*-not-moved)
|
constexpr box(box<U, Allocator>&& other) // NOLINT(*explicit*,*-not-moved)
|
||||||
: m_ptr{exchange(other.m_ptr, nullptr)}
|
: m_ptr{exchange(other.m_ptr, nullptr)}
|
||||||
, m_alloc{std::move(other.m_alloc)}
|
, m_alloc{std::move(other.m_alloc)}
|
||||||
|
@ -94,10 +94,10 @@ public:
|
|||||||
int number() override { return 2; }
|
int number() override { return 2; }
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert(asl::convertible_from<asl::box<Base>, asl::box<Derived>>);
|
static_assert(asl::convertible_to<asl::box<Derived>, asl::box<Base>>);
|
||||||
static_assert(asl::convertible_from<asl::box<Base>, asl::box<Base>>);
|
static_assert(asl::convertible_to<asl::box<Base>, asl::box<Base>>);
|
||||||
static_assert(!asl::convertible_from<asl::box<Derived>, asl::box<Base>>);
|
static_assert(!asl::convertible_to<asl::box<Base>, asl::box<Derived>>);
|
||||||
static_assert(!asl::convertible_from<asl::box<int>, asl::box<float>>);
|
static_assert(!asl::convertible_to<asl::box<float>, asl::box<int>>);
|
||||||
|
|
||||||
ASL_TEST(derived)
|
ASL_TEST(derived)
|
||||||
{
|
{
|
||||||
|
@ -110,7 +110,7 @@ public:
|
|||||||
constexpr option(nullopt_t) requires kHasNiche : m_payload{in_place, niche_t{}} {}
|
constexpr option(nullopt_t) requires kHasNiche : m_payload{in_place, niche_t{}} {}
|
||||||
|
|
||||||
template<typename U = T>
|
template<typename U = T>
|
||||||
constexpr explicit (!convertible_from<T, U&&>)
|
constexpr explicit (!convertible_to<U&&, T>)
|
||||||
option(U&& value)
|
option(U&& value)
|
||||||
requires (
|
requires (
|
||||||
kHasNiche &&
|
kHasNiche &&
|
||||||
@ -121,7 +121,7 @@ public:
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
template<typename U = T>
|
template<typename U = T>
|
||||||
constexpr explicit (!convertible_from<T, U&&>)
|
constexpr explicit (!convertible_to<U&&, T>)
|
||||||
option(U&& value)
|
option(U&& value)
|
||||||
requires (
|
requires (
|
||||||
!kHasNiche &&
|
!kHasNiche &&
|
||||||
@ -159,7 +159,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename U>
|
template<typename U>
|
||||||
constexpr explicit (!convertible_from<T, const U&>)
|
constexpr explicit (!convertible_to<const U&, T>)
|
||||||
option(const option<U>& other)
|
option(const option<U>& other)
|
||||||
requires (
|
requires (
|
||||||
constructible_from<T, const U&> &&
|
constructible_from<T, const U&> &&
|
||||||
@ -174,7 +174,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename U>
|
template<typename U>
|
||||||
constexpr explicit (!convertible_from<T, U&&>)
|
constexpr explicit (!convertible_to<U&&, T>)
|
||||||
option(option<U>&& other)
|
option(option<U>&& other)
|
||||||
requires (
|
requires (
|
||||||
constructible_from<T, U&&> &&
|
constructible_from<T, U&&> &&
|
||||||
@ -377,14 +377,14 @@ public:
|
|||||||
|
|
||||||
template<typename U>
|
template<typename U>
|
||||||
constexpr T value_or(U&& other_value) const&
|
constexpr T value_or(U&& other_value) const&
|
||||||
requires copy_constructible<T> && convertible_from<T, U&&>
|
requires copy_constructible<T> && convertible_to<U&&, T>
|
||||||
{
|
{
|
||||||
return has_value() ? value() : static_cast<T>(std::forward<U>(other_value));
|
return has_value() ? value() : static_cast<T>(std::forward<U>(other_value));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U>
|
template<typename U>
|
||||||
constexpr T value_or(U&& other_value) &&
|
constexpr T value_or(U&& other_value) &&
|
||||||
requires move_constructible<T> && convertible_from<T, U&&>
|
requires move_constructible<T> && convertible_to<U&&, T>
|
||||||
{
|
{
|
||||||
return has_value() ? std::move(value()) : static_cast<T>(std::forward<U>(other_value));
|
return has_value() ? std::move(value()) : static_cast<T>(std::forward<U>(other_value));
|
||||||
}
|
}
|
||||||
|
@ -62,20 +62,20 @@ static_assert(!asl::move_assignable<asl::option<Pinned>>);
|
|||||||
static_assert(asl::assignable_from<asl::option<Base*>&, asl::option<Derived*>>);
|
static_assert(asl::assignable_from<asl::option<Base*>&, asl::option<Derived*>>);
|
||||||
static_assert(!asl::assignable_from<asl::option<Derived*>&, asl::option<Base*>>);
|
static_assert(!asl::assignable_from<asl::option<Derived*>&, asl::option<Base*>>);
|
||||||
|
|
||||||
static_assert(asl::convertible_from<asl::option<Base*>, asl::option<Derived*>>);
|
static_assert(asl::convertible_to<asl::option<Derived*>, asl::option<Base*>>);
|
||||||
static_assert(!asl::convertible_from<asl::option<Derived*>, asl::option<Base*>>);
|
static_assert(!asl::convertible_to<asl::option<Base*>, asl::option<Derived*>>);
|
||||||
|
|
||||||
class ExplicitConversion { public: explicit ExplicitConversion(int) {} };
|
class ExplicitConversion { public: explicit ExplicitConversion(int) {} };
|
||||||
class ImplicitConversion { public: ImplicitConversion(int) {} }; // NOLINT
|
class ImplicitConversion { public: ImplicitConversion(int) {} }; // NOLINT
|
||||||
|
|
||||||
static_assert(!asl::convertible_from<ExplicitConversion, int>);
|
static_assert(!asl::convertible_to<int, ExplicitConversion>);
|
||||||
static_assert(asl::convertible_from<ImplicitConversion, int>);
|
static_assert(asl::convertible_to<int, ImplicitConversion>);
|
||||||
|
|
||||||
static_assert(!asl::convertible_from<asl::option<ExplicitConversion>, int>);
|
static_assert(!asl::convertible_to<int, asl::option<ExplicitConversion>>);
|
||||||
static_assert(asl::convertible_from<asl::option<ImplicitConversion>, int>);
|
static_assert(asl::convertible_to<int, asl::option<ImplicitConversion>>);
|
||||||
|
|
||||||
static_assert(!asl::convertible_from<asl::option<ExplicitConversion>, asl::option<int>>);
|
static_assert(!asl::convertible_to<asl::option<int>, asl::option<ExplicitConversion>>);
|
||||||
static_assert(asl::convertible_from<asl::option<ImplicitConversion>, asl::option<int>>);
|
static_assert(asl::convertible_to<asl::option<int>, asl::option<ImplicitConversion>>);
|
||||||
|
|
||||||
static_assert(asl::trivially_copy_constructible<asl::option<int>>);
|
static_assert(asl::trivially_copy_constructible<asl::option<int>>);
|
||||||
static_assert(asl::trivially_copy_constructible<asl::option<TrivialType>>);
|
static_assert(asl::trivially_copy_constructible<asl::option<TrivialType>>);
|
||||||
|
@ -95,7 +95,7 @@ public:
|
|||||||
kIsDynamic ||
|
kIsDynamic ||
|
||||||
is_dynamic(kOtherSize) ||
|
is_dynamic(kOtherSize) ||
|
||||||
kOtherSize == kSize
|
kOtherSize == kSize
|
||||||
) && convertible_from<T(&)[], U(&)[]>
|
) && convertible_to<U(&)[], T(&)[]>
|
||||||
)
|
)
|
||||||
: span{static_cast<U*>(other.data()), other.size()}
|
: span{static_cast<U*>(other.data()), other.size()}
|
||||||
{
|
{
|
||||||
|
@ -114,7 +114,7 @@ public:
|
|||||||
status_or& operator=(status status) = delete;
|
status_or& operator=(status status) = delete;
|
||||||
|
|
||||||
template<typename U = T>
|
template<typename U = T>
|
||||||
constexpr explicit (!convertible_from<T, U&&>)
|
constexpr explicit (!convertible_to<U&&, T>)
|
||||||
status_or(U&& value)
|
status_or(U&& value)
|
||||||
requires (
|
requires (
|
||||||
constructible_from<T, U&&> &&
|
constructible_from<T, U&&> &&
|
||||||
@ -141,14 +141,14 @@ public:
|
|||||||
|
|
||||||
template<typename U>
|
template<typename U>
|
||||||
constexpr T value_or(U&& other_value) const&
|
constexpr T value_or(U&& other_value) const&
|
||||||
requires copy_constructible<T> && convertible_from<T, U&&>
|
requires copy_constructible<T> && convertible_to<U&&, T>
|
||||||
{
|
{
|
||||||
return ok() ? value() : static_cast<T>(std::forward<U>(other_value));
|
return ok() ? value() : static_cast<T>(std::forward<U>(other_value));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U>
|
template<typename U>
|
||||||
constexpr T value_or(U&& other_value) &&
|
constexpr T value_or(U&& other_value) &&
|
||||||
requires move_constructible<T> && convertible_from<T, U&&>
|
requires move_constructible<T> && convertible_to<U&&, T>
|
||||||
{
|
{
|
||||||
return ok() ? std::move(value()) : static_cast<T>(std::forward<U>(other_value));
|
return ok() ? std::move(value()) : static_cast<T>(std::forward<U>(other_value));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user