diff --git a/README.md b/README.md index 81cb9b2..904be69 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ PRO_DEF_FREE_DISPATCH(Call, std::invoke, Overloads...); template PRO_DEF_FACADE(MovableCallable, Call); template -PRO_DEF_FACADE(CopyableCallable, Call, pro::copyable_pointer_constraints); +PRO_DEF_FACADE(CopyableCallable, Call, pro::copyable_ptr_constraints); } // namespace poly diff --git a/proxy.h b/proxy.h index f947804..ec5b700 100644 --- a/proxy.h +++ b/proxy.h @@ -16,33 +16,33 @@ namespace pro { enum class constraint_level { none, nontrivial, nothrow, trivial }; -struct proxy_pointer_constraints { - std::size_t maximum_size; - std::size_t maximum_alignment; - constraint_level minimum_copyability; - constraint_level minimum_relocatability; - constraint_level minimum_destructibility; +struct proxiable_ptr_constraints { + std::size_t max_size; + std::size_t max_align; + constraint_level copyability; + constraint_level relocatability; + constraint_level destructibility; }; -constexpr proxy_pointer_constraints relocatable_pointer_constraints{ - .maximum_size = sizeof(void*) * 2u, - .maximum_alignment = alignof(void*), - .minimum_copyability = constraint_level::none, - .minimum_relocatability = constraint_level::nothrow, - .minimum_destructibility = constraint_level::nothrow, +constexpr proxiable_ptr_constraints relocatable_ptr_constraints{ + .max_size = sizeof(void*) * 2u, + .max_align = alignof(void*), + .copyability = constraint_level::none, + .relocatability = constraint_level::nothrow, + .destructibility = constraint_level::nothrow, }; -constexpr proxy_pointer_constraints copyable_pointer_constraints{ - .maximum_size = sizeof(void*) * 2u, - .maximum_alignment = alignof(void*), - .minimum_copyability = constraint_level::nontrivial, - .minimum_relocatability = constraint_level::nothrow, - .minimum_destructibility = constraint_level::nothrow, +constexpr proxiable_ptr_constraints copyable_ptr_constraints{ + .max_size = sizeof(void*) * 2u, + .max_align = alignof(void*), + .copyability = constraint_level::nontrivial, + .relocatability = constraint_level::nothrow, + .destructibility = constraint_level::nothrow, }; -constexpr proxy_pointer_constraints trivial_pointer_constraints{ - .maximum_size = sizeof(void*), - .maximum_alignment = alignof(void*), - .minimum_copyability = constraint_level::trivial, - .minimum_relocatability = constraint_level::trivial, - .minimum_destructibility = constraint_level::trivial, +constexpr proxiable_ptr_constraints trivial_ptr_constraints{ + .max_size = sizeof(void*), + .max_align = alignof(void*), + .copyability = constraint_level::trivial, + .relocatability = constraint_level::trivial, + .destructibility = constraint_level::trivial, }; namespace details { @@ -257,12 +257,9 @@ template struct basic_facade_traits_impl; template struct basic_facade_traits_impl> { using meta_type = typename facade_meta_traits< - conditional_meta_tag< - F::pointer_constraints.minimum_copyability, copy_meta>, - conditional_meta_tag< - F::pointer_constraints.minimum_relocatability, relocation_meta>, - conditional_meta_tag< - F::pointer_constraints.minimum_destructibility, destruction_meta>, + conditional_meta_tag, + conditional_meta_tag, + conditional_meta_tag, conditional_meta_tag ? constraint_level::none : constraint_level::nothrow, typename F::reflection_type>>::type; @@ -284,11 +281,11 @@ struct facade_traits_impl> : applicable_traits { template static constexpr bool applicable_pointer = - sizeof(P) <= F::pointer_constraints.maximum_size && - alignof(P) <= F::pointer_constraints.maximum_alignment && - has_copyability

(F::pointer_constraints.minimum_copyability) && - has_relocatability

(F::pointer_constraints.minimum_relocatability) && - has_destructibility

(F::pointer_constraints.minimum_destructibility) && + sizeof(P) <= F::constraints.max_size && + alignof(P) <= F::constraints.max_align && + has_copyability

(F::constraints.copyability) && + has_relocatability

(F::constraints.relocatability) && + has_destructibility

(F::constraints.destructibility) && (dispatch_traits::template applicable_pointer

&& ...) && (std::is_void_v || std::is_constructible_v< typename F::reflection_type, std::in_place_type_t

>); @@ -306,8 +303,7 @@ using dependent_t = typename dependent_traits::type; template concept basic_facade = requires { typename F::dispatch_types; - typename std::integral_constant< - proxy_pointer_constraints, F::pointer_constraints>; + typename std::integral_constant; typename F::reflection_type; }; @@ -333,21 +329,21 @@ class proxy { proxiable, std::is_constructible, std::false_type>::value; static constexpr bool HasTrivialCopyConstructor = - F::pointer_constraints.minimum_copyability == constraint_level::trivial; + F::constraints.copyability == constraint_level::trivial; static constexpr bool HasNothrowCopyConstructor = - F::pointer_constraints.minimum_copyability >= constraint_level::nothrow; - static constexpr bool HasCopyConstructor = F::pointer_constraints - .minimum_copyability >= constraint_level::nontrivial; - static constexpr bool HasNothrowMoveConstructor = F::pointer_constraints - .minimum_relocatability >= constraint_level::nothrow; - static constexpr bool HasMoveConstructor = F::pointer_constraints - .minimum_relocatability >= constraint_level::nontrivial; - static constexpr bool HasTrivialDestructor = F::pointer_constraints - .minimum_destructibility == constraint_level::trivial; - static constexpr bool HasNothrowDestructor = F::pointer_constraints - .minimum_destructibility >= constraint_level::nothrow; - static constexpr bool HasDestructor = F::pointer_constraints - .minimum_destructibility >= constraint_level::nontrivial; + F::constraints.copyability >= constraint_level::nothrow; + static constexpr bool HasCopyConstructor = + F::constraints.copyability >= constraint_level::nontrivial; + static constexpr bool HasNothrowMoveConstructor = + F::constraints.relocatability >= constraint_level::nothrow; + static constexpr bool HasMoveConstructor = + F::constraints.relocatability >= constraint_level::nontrivial; + static constexpr bool HasTrivialDestructor = + F::constraints.destructibility == constraint_level::trivial; + static constexpr bool HasNothrowDestructor = + F::constraints.destructibility >= constraint_level::nothrow; + static constexpr bool HasDestructor = + F::constraints.destructibility >= constraint_level::nontrivial; template static constexpr bool HasNothrowPolyAssignment = HasNothrowPolyConstructor && HasNothrowDestructor; @@ -381,9 +377,9 @@ class proxy { proxy(proxy&& rhs) noexcept(HasNothrowMoveConstructor) requires(HasMoveConstructor) { if (rhs.meta_ != nullptr) { - if constexpr (F::pointer_constraints.minimum_relocatability == + if constexpr (F::constraints.relocatability == constraint_level::trivial) { - memcpy(ptr_, rhs.ptr_, F::pointer_constraints.maximum_size); + memcpy(ptr_, rhs.ptr_, F::constraints.max_size); } else { rhs.meta_->relocate(ptr_, rhs.ptr_); } @@ -469,8 +465,7 @@ class proxy { { this->~proxy(); meta_ = nullptr; } void swap(proxy& rhs) noexcept(HasNothrowMoveConstructor) requires(HasMoveConstructor) { - if constexpr (F::pointer_constraints.minimum_relocatability == - constraint_level::trivial) { + if constexpr (F::constraints.relocatability == constraint_level::trivial) { std::swap(meta_, rhs.meta_); std::swap(ptr_, rhs.ptr); } else { @@ -533,8 +528,7 @@ class proxy { } const typename BasicTraits::meta_type* meta_; - alignas(F::pointer_constraints.maximum_alignment) - char ptr_[F::pointer_constraints.maximum_size]; + alignas(F::constraints.max_align) char ptr_[F::constraints.max_size]; }; namespace details { @@ -598,11 +592,11 @@ proxy make_proxy(T&& value) { // facade types prior to C++26 namespace helper { -template , proxy_pointer_constraints C = - relocatable_pointer_constraints, class R = void> +template , proxiable_ptr_constraints C = + relocatable_ptr_constraints, class R = void> struct facade_prototype { using dispatch_types = D; - static constexpr proxy_pointer_constraints pointer_constraints = C; + static constexpr proxiable_ptr_constraints constraints = C; using reflection_type = R; }; diff --git a/tests/proxy_creation_tests.cpp b/tests/proxy_creation_tests.cpp index f863799..59ce064 100644 --- a/tests/proxy_creation_tests.cpp +++ b/tests/proxy_creation_tests.cpp @@ -21,14 +21,14 @@ struct SboObserver { bool SboEnabled; }; -PRO_DEF_FACADE(TestSmallStringable, utils::poly::ToString, pro::proxy_pointer_constraints{ - .maximum_size = sizeof(void*), - .maximum_alignment = alignof(void*), - .minimum_copyability = pro::constraint_level::nontrivial, - .minimum_relocatability = pro::constraint_level::nothrow, - .minimum_destructibility = pro::constraint_level::nothrow, +PRO_DEF_FACADE(TestSmallStringable, utils::poly::ToString, pro::proxiable_ptr_constraints{ + .max_size = sizeof(void*), + .max_align = alignof(void*), + .copyability = pro::constraint_level::nontrivial, + .relocatability = pro::constraint_level::nothrow, + .destructibility = pro::constraint_level::nothrow, }, SboObserver); -PRO_DEF_FACADE(TestLargeStringable, utils::poly::ToString, pro::copyable_pointer_constraints, SboObserver); +PRO_DEF_FACADE(TestLargeStringable, utils::poly::ToString, pro::copyable_ptr_constraints, SboObserver); } // namespace poly diff --git a/tests/proxy_invocation_tests.cpp b/tests/proxy_invocation_tests.cpp index 99cea48..d6d2e25 100644 --- a/tests/proxy_invocation_tests.cpp +++ b/tests/proxy_invocation_tests.cpp @@ -18,7 +18,7 @@ namespace poly { template PRO_DEF_FREE_DISPATCH(Call, std::invoke, Os...); template -PRO_DEF_FACADE(Callable, Call, pro::copyable_pointer_constraints); +PRO_DEF_FACADE(Callable, Call, pro::copyable_ptr_constraints); PRO_DEF_FREE_DISPATCH(GetSize, std::ranges::size, std::size_t()); diff --git a/tests/proxy_lifetime_tests.cpp b/tests/proxy_lifetime_tests.cpp index cee2306..429c741 100644 --- a/tests/proxy_lifetime_tests.cpp +++ b/tests/proxy_lifetime_tests.cpp @@ -7,7 +7,7 @@ namespace { -PRO_DEF_FACADE(TestFacade, utils::poly::ToString, pro::copyable_pointer_constraints); +PRO_DEF_FACADE(TestFacade, utils::poly::ToString, pro::copyable_ptr_constraints); } // namespace diff --git a/tests/proxy_reflection_tests.cpp b/tests/proxy_reflection_tests.cpp index 5a65385..3593636 100644 --- a/tests/proxy_reflection_tests.cpp +++ b/tests/proxy_reflection_tests.cpp @@ -45,10 +45,10 @@ struct TraitsReflection { PRO_DEF_FACADE(DefaultFacade); static_assert(!ReflectionApplicable); -PRO_DEF_FACADE(TestRttiFacade, PRO_MAKE_DISPATCH_PACK(), pro::relocatable_pointer_constraints, RttiReflection); +PRO_DEF_FACADE(TestRttiFacade, PRO_MAKE_DISPATCH_PACK(), pro::relocatable_ptr_constraints, RttiReflection); static_assert(ReflectionApplicable); -PRO_DEF_FACADE(TestTraitsFacade, PRO_MAKE_DISPATCH_PACK(), pro::relocatable_pointer_constraints, TraitsReflection); +PRO_DEF_FACADE(TestTraitsFacade, PRO_MAKE_DISPATCH_PACK(), pro::relocatable_ptr_constraints, TraitsReflection); static_assert(ReflectionApplicable); } // namespace diff --git a/tests/proxy_traits_tests.cpp b/tests/proxy_traits_tests.cpp index 4a34658..720181a 100644 --- a/tests/proxy_traits_tests.cpp +++ b/tests/proxy_traits_tests.cpp @@ -25,11 +25,11 @@ using MockTrivialPtr = MockPtr; using MockFunctionPtr = void(*)(); PRO_DEF_FACADE(DefaultFacade); -static_assert(DefaultFacade::pointer_constraints.minimum_copyability == pro::constraint_level::none); -static_assert(DefaultFacade::pointer_constraints.minimum_relocatability == pro::constraint_level::nothrow); -static_assert(DefaultFacade::pointer_constraints.minimum_destructibility == pro::constraint_level::nothrow); -static_assert(DefaultFacade::pointer_constraints.maximum_size >= 2 * sizeof(void*)); -static_assert(DefaultFacade::pointer_constraints.maximum_alignment >= sizeof(void*)); +static_assert(DefaultFacade::constraints.copyability == pro::constraint_level::none); +static_assert(DefaultFacade::constraints.relocatability == pro::constraint_level::nothrow); +static_assert(DefaultFacade::constraints.destructibility == pro::constraint_level::nothrow); +static_assert(DefaultFacade::constraints.max_size >= 2 * sizeof(void*)); +static_assert(DefaultFacade::constraints.max_align >= sizeof(void*)); static_assert(std::is_same_v>); static_assert(std::is_same_v); static_assert(std::is_nothrow_default_constructible_v>); @@ -69,7 +69,7 @@ static_assert(std::is_nothrow_assignable_v, MockTr static_assert(std::is_nothrow_constructible_v, MockFunctionPtr>); static_assert(std::is_nothrow_assignable_v, MockFunctionPtr>); -PRO_DEF_FACADE(CopyableFacade, PRO_MAKE_DISPATCH_PACK(), pro::copyable_pointer_constraints); +PRO_DEF_FACADE(CopyableFacade, PRO_MAKE_DISPATCH_PACK(), pro::copyable_ptr_constraints); static_assert(std::is_copy_constructible_v>); static_assert(!std::is_nothrow_copy_constructible_v>); static_assert(std::is_copy_assignable_v>); @@ -96,12 +96,12 @@ static_assert(std::is_nothrow_assignable_v, MockTrivi static_assert(std::is_nothrow_constructible_v, MockFunctionPtr>); static_assert(std::is_nothrow_assignable_v, MockFunctionPtr>); -PRO_DEF_FACADE(CopyableSmallFacade, PRO_MAKE_DISPATCH_PACK(), pro::proxy_pointer_constraints{ - .maximum_size = sizeof(void*), - .maximum_alignment = alignof(void*), - .minimum_copyability = pro::constraint_level::nontrivial, - .minimum_relocatability = pro::constraint_level::nothrow, - .minimum_destructibility = pro::constraint_level::nothrow, +PRO_DEF_FACADE(CopyableSmallFacade, PRO_MAKE_DISPATCH_PACK(), pro::proxiable_ptr_constraints{ + .max_size = sizeof(void*), + .max_align = alignof(void*), + .copyability = pro::constraint_level::nontrivial, + .relocatability = pro::constraint_level::nothrow, + .destructibility = pro::constraint_level::nothrow, }); static_assert(!pro::proxiable); static_assert(!pro::proxiable); @@ -119,7 +119,7 @@ static_assert(std::is_assignable_v, MockTrivialP static_assert(std::is_constructible_v, MockFunctionPtr>); static_assert(std::is_assignable_v, MockFunctionPtr>); -PRO_DEF_FACADE(TrivialFacade, PRO_MAKE_DISPATCH_PACK(), pro::trivial_pointer_constraints); +PRO_DEF_FACADE(TrivialFacade, PRO_MAKE_DISPATCH_PACK(), pro::trivial_ptr_constraints); static_assert(std::is_trivially_copy_constructible_v>); static_assert(std::is_trivially_copy_assignable_v>); static_assert(std::is_nothrow_move_constructible_v>);