From c8b73031d8a9f7770410c9d0e6da5b230e501e85 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Wed, 12 Mar 2025 00:08:18 +0100 Subject: Remove convertible_from --- asl/base/meta.hpp | 7 ++----- asl/base/meta_tests.cpp | 26 +++++++++++++------------- asl/types/box.hpp | 2 +- asl/types/box_tests.cpp | 8 ++++---- asl/types/option.hpp | 12 ++++++------ asl/types/option_tests.cpp | 16 ++++++++-------- asl/types/span.hpp | 2 +- asl/types/status_or.hpp | 6 +++--- todo.txt | 2 +- 9 files changed, 39 insertions(+), 42 deletions(-) diff --git a/asl/base/meta.hpp b/asl/base/meta.hpp index 8376d5c..8bebf2f 100644 --- a/asl/base/meta.hpp +++ b/asl/base/meta.hpp @@ -87,14 +87,11 @@ template concept trivially_destructible = __is_trivially_destructibl template concept copyable = copy_constructible && copy_assignable; template concept moveable = move_constructible && move_assignable; -template -concept convertible_from = __is_convertible(From, To); - template concept convertible_to = __is_convertible(From, To); template -concept derived_from = __is_class(Derived) && __is_class(Base) && convertible_from; +concept derived_from = __is_class(Derived) && __is_class(Base) && convertible_to; using nullptr_t = decltype(nullptr); @@ -258,7 +255,7 @@ concept derefs_as = is_object && (convertible_to&, To&> || _dereferenceable_as_convertible, To>); template From> -constexpr auto&& deref(From&& from) // NOLINT(*forward*) +constexpr auto&& deref(From&& from) // NOLINT(*-missing-std-forward) { if constexpr (_dereferenceable_as_convertible) { diff --git a/asl/base/meta_tests.cpp b/asl/base/meta_tests.cpp index 6c8efab..490b453 100644 --- a/asl/base/meta_tests.cpp +++ b/asl/base/meta_tests.cpp @@ -205,19 +205,19 @@ class C {}; class D { public: operator C() { return c; } C c; }; // NOLINT class E { public: template E(T&&) {} }; // NOLINT -static_assert(asl::convertible_from); -static_assert(!asl::convertible_from); -static_assert(asl::convertible_from); -static_assert(!asl::convertible_from); -static_assert(asl::convertible_from); - -static_assert(!asl::convertible_from); -static_assert(asl::convertible_from); -static_assert(asl::convertible_from); -static_assert(asl::convertible_from); -static_assert(!asl::convertible_from); -static_assert(!asl::convertible_from); -static_assert(!asl::convertible_from); +static_assert(asl::convertible_to); +static_assert(!asl::convertible_to); +static_assert(asl::convertible_to); +static_assert(!asl::convertible_to); +static_assert(asl::convertible_to); + +static_assert(!asl::convertible_to); +static_assert(asl::convertible_to); +static_assert(asl::convertible_to); +static_assert(asl::convertible_to); +static_assert(!asl::convertible_to); +static_assert(!asl::convertible_to); +static_assert(!asl::convertible_to); static_assert(asl::derived_from); static_assert(!asl::derived_from); diff --git a/asl/types/box.hpp b/asl/types/box.hpp index bb4e620..82704d7 100644 --- a/asl/types/box.hpp +++ b/asl/types/box.hpp @@ -40,7 +40,7 @@ public: {} template - requires convertible_from + requires convertible_to constexpr box(box&& other) // NOLINT(*explicit*,*-not-moved) : m_ptr{exchange(other.m_ptr, nullptr)} , m_alloc{std::move(other.m_alloc)} diff --git a/asl/types/box_tests.cpp b/asl/types/box_tests.cpp index b3c55b2..1ee5f0e 100644 --- a/asl/types/box_tests.cpp +++ b/asl/types/box_tests.cpp @@ -94,10 +94,10 @@ public: int number() override { return 2; } }; -static_assert(asl::convertible_from, asl::box>); -static_assert(asl::convertible_from, asl::box>); -static_assert(!asl::convertible_from, asl::box>); -static_assert(!asl::convertible_from, asl::box>); +static_assert(asl::convertible_to, asl::box>); +static_assert(asl::convertible_to, asl::box>); +static_assert(!asl::convertible_to, asl::box>); +static_assert(!asl::convertible_to, asl::box>); ASL_TEST(derived) { diff --git a/asl/types/option.hpp b/asl/types/option.hpp index 9c317b0..982c63d 100644 --- a/asl/types/option.hpp +++ b/asl/types/option.hpp @@ -110,7 +110,7 @@ public: constexpr option(nullopt_t) requires kHasNiche : m_payload{in_place, niche_t{}} {} template - constexpr explicit (!convertible_from) + constexpr explicit (!convertible_to) option(U&& value) requires ( kHasNiche && @@ -121,7 +121,7 @@ public: {} template - constexpr explicit (!convertible_from) + constexpr explicit (!convertible_to) option(U&& value) requires ( !kHasNiche && @@ -159,7 +159,7 @@ public: } template - constexpr explicit (!convertible_from) + constexpr explicit (!convertible_to) option(const option& other) requires ( constructible_from && @@ -174,7 +174,7 @@ public: } template - constexpr explicit (!convertible_from) + constexpr explicit (!convertible_to) option(option&& other) requires ( constructible_from && @@ -377,14 +377,14 @@ public: template constexpr T value_or(U&& other_value) const& - requires copy_constructible && convertible_from + requires copy_constructible && convertible_to { return has_value() ? value() : static_cast(std::forward(other_value)); } template constexpr T value_or(U&& other_value) && - requires move_constructible && convertible_from + requires move_constructible && convertible_to { return has_value() ? std::move(value()) : static_cast(std::forward(other_value)); } diff --git a/asl/types/option_tests.cpp b/asl/types/option_tests.cpp index d08c94a..64ddfa6 100644 --- a/asl/types/option_tests.cpp +++ b/asl/types/option_tests.cpp @@ -62,20 +62,20 @@ static_assert(!asl::move_assignable>); static_assert(asl::assignable_from&, asl::option>); static_assert(!asl::assignable_from&, asl::option>); -static_assert(asl::convertible_from, asl::option>); -static_assert(!asl::convertible_from, asl::option>); +static_assert(asl::convertible_to, asl::option>); +static_assert(!asl::convertible_to, asl::option>); class ExplicitConversion { public: explicit ExplicitConversion(int) {} }; class ImplicitConversion { public: ImplicitConversion(int) {} }; // NOLINT -static_assert(!asl::convertible_from); -static_assert(asl::convertible_from); +static_assert(!asl::convertible_to); +static_assert(asl::convertible_to); -static_assert(!asl::convertible_from, int>); -static_assert(asl::convertible_from, int>); +static_assert(!asl::convertible_to>); +static_assert(asl::convertible_to>); -static_assert(!asl::convertible_from, asl::option>); -static_assert(asl::convertible_from, asl::option>); +static_assert(!asl::convertible_to, asl::option>); +static_assert(asl::convertible_to, asl::option>); static_assert(asl::trivially_copy_constructible>); static_assert(asl::trivially_copy_constructible>); diff --git a/asl/types/span.hpp b/asl/types/span.hpp index bb2257a..8585f17 100644 --- a/asl/types/span.hpp +++ b/asl/types/span.hpp @@ -95,7 +95,7 @@ public: kIsDynamic || is_dynamic(kOtherSize) || kOtherSize == kSize - ) && convertible_from + ) && convertible_to ) : span{static_cast(other.data()), other.size()} { diff --git a/asl/types/status_or.hpp b/asl/types/status_or.hpp index be6bb06..7794596 100644 --- a/asl/types/status_or.hpp +++ b/asl/types/status_or.hpp @@ -114,7 +114,7 @@ public: status_or& operator=(status status) = delete; template - constexpr explicit (!convertible_from) + constexpr explicit (!convertible_to) status_or(U&& value) requires ( constructible_from && @@ -141,14 +141,14 @@ public: template constexpr T value_or(U&& other_value) const& - requires copy_constructible && convertible_from + requires copy_constructible && convertible_to { return ok() ? value() : static_cast(std::forward(other_value)); } template constexpr T value_or(U&& other_value) && - requires move_constructible && convertible_from + requires move_constructible && convertible_to { return ok() ? std::move(value()) : static_cast(std::forward(other_value)); } diff --git a/todo.txt b/todo.txt index 9a88465..8b13789 100644 --- a/todo.txt +++ b/todo.txt @@ -1 +1 @@ -remove convertible_from + -- cgit