Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
mingxwa committed Dec 26, 2023
1 parent 30c87ef commit 254628b
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 85 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ PRO_DEF_FREE_DISPATCH(Call, std::invoke, Overloads...);
template <class... Overloads>
PRO_DEF_FACADE(MovableCallable, Call<Overloads...>);
template <class... Overloads>
PRO_DEF_FACADE(CopyableCallable, Call<Overloads...>, pro::copyable_pointer_constraints);
PRO_DEF_FACADE(CopyableCallable, Call<Overloads...>, pro::copyable_ptr_constraints);

} // namespace poly

Expand Down
114 changes: 54 additions & 60 deletions proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -257,12 +257,9 @@ template <class F, class Ds> struct basic_facade_traits_impl;
template <class F, class... Ds>
struct basic_facade_traits_impl<F, std::tuple<Ds...>> {
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<F::constraints.copyability, copy_meta>,
conditional_meta_tag<F::constraints.relocatability, relocation_meta>,
conditional_meta_tag<F::constraints.destructibility, destruction_meta>,
conditional_meta_tag<std::is_void_v<typename F::reflection_type> ?
constraint_level::none : constraint_level::nothrow,
typename F::reflection_type>>::type;
Expand All @@ -284,11 +281,11 @@ struct facade_traits_impl<F, std::tuple<Ds...>> : applicable_traits {

template <class P>
static constexpr bool applicable_pointer =
sizeof(P) <= F::pointer_constraints.maximum_size &&
alignof(P) <= F::pointer_constraints.maximum_alignment &&
has_copyability<P>(F::pointer_constraints.minimum_copyability) &&
has_relocatability<P>(F::pointer_constraints.minimum_relocatability) &&
has_destructibility<P>(F::pointer_constraints.minimum_destructibility) &&
sizeof(P) <= F::constraints.max_size &&
alignof(P) <= F::constraints.max_align &&
has_copyability<P>(F::constraints.copyability) &&
has_relocatability<P>(F::constraints.relocatability) &&
has_destructibility<P>(F::constraints.destructibility) &&
(dispatch_traits<Ds>::template applicable_pointer<P> && ...) &&
(std::is_void_v<typename F::reflection_type> || std::is_constructible_v<
typename F::reflection_type, std::in_place_type_t<P>>);
Expand All @@ -306,8 +303,7 @@ using dependent_t = typename dependent_traits<T, Us...>::type;
template <class F>
concept basic_facade = requires {
typename F::dispatch_types;
typename std::integral_constant<
proxy_pointer_constraints, F::pointer_constraints>;
typename std::integral_constant<proxiable_ptr_constraints, F::constraints>;
typename F::reflection_type;
};

Expand All @@ -333,21 +329,21 @@ class proxy {
proxiable<P, F>, std::is_constructible<P, Args...>,
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 <class P, class... Args>
static constexpr bool HasNothrowPolyAssignment =
HasNothrowPolyConstructor<P, Args...> && HasNothrowDestructor;
Expand Down Expand Up @@ -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_);
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -598,11 +592,11 @@ proxy<F> make_proxy(T&& value) {
// facade types prior to C++26
namespace helper {

template <class D = std::tuple<>, proxy_pointer_constraints C =
relocatable_pointer_constraints, class R = void>
template <class D = std::tuple<>, 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;
};

Expand Down
14 changes: 7 additions & 7 deletions tests/proxy_creation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/proxy_invocation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace poly {
template <class... Os>
PRO_DEF_FREE_DISPATCH(Call, std::invoke, Os...);
template <class... Os>
PRO_DEF_FACADE(Callable, Call<Os...>, pro::copyable_pointer_constraints);
PRO_DEF_FACADE(Callable, Call<Os...>, pro::copyable_ptr_constraints);

PRO_DEF_FREE_DISPATCH(GetSize, std::ranges::size, std::size_t());

Expand Down
2 changes: 1 addition & 1 deletion tests/proxy_lifetime_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions tests/proxy_reflection_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ struct TraitsReflection {
PRO_DEF_FACADE(DefaultFacade);
static_assert(!ReflectionApplicable<DefaultFacade>);

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<TestRttiFacade>);

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<TestTraitsFacade>);

} // namespace
Expand Down
26 changes: 13 additions & 13 deletions tests/proxy_traits_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ using MockTrivialPtr = MockPtr<true, true, true, sizeof(void*), alignof(void*)>;
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<DefaultFacade::dispatch_types, std::tuple<>>);
static_assert(std::is_same_v<DefaultFacade::reflection_type, void>);
static_assert(std::is_nothrow_default_constructible_v<pro::proxy<DefaultFacade>>);
Expand Down Expand Up @@ -69,7 +69,7 @@ static_assert(std::is_nothrow_assignable_v<pro::proxy<RelocatableFacade>, MockTr
static_assert(std::is_nothrow_constructible_v<pro::proxy<RelocatableFacade>, MockFunctionPtr>);
static_assert(std::is_nothrow_assignable_v<pro::proxy<RelocatableFacade>, 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<pro::proxy<CopyableFacade>>);
static_assert(!std::is_nothrow_copy_constructible_v<pro::proxy<CopyableFacade>>);
static_assert(std::is_copy_assignable_v<pro::proxy<CopyableFacade>>);
Expand All @@ -96,12 +96,12 @@ static_assert(std::is_nothrow_assignable_v<pro::proxy<CopyableFacade>, MockTrivi
static_assert(std::is_nothrow_constructible_v<pro::proxy<CopyableFacade>, MockFunctionPtr>);
static_assert(std::is_nothrow_assignable_v<pro::proxy<CopyableFacade>, 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<MockMovablePtr, CopyableSmallFacade>);
static_assert(!pro::proxiable<MockCopyablePtr, CopyableSmallFacade>);
Expand All @@ -119,7 +119,7 @@ static_assert(std::is_assignable_v<pro::proxy<CopyableSmallFacade>, MockTrivialP
static_assert(std::is_constructible_v<pro::proxy<CopyableSmallFacade>, MockFunctionPtr>);
static_assert(std::is_assignable_v<pro::proxy<CopyableSmallFacade>, 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<pro::proxy<TrivialFacade>>);
static_assert(std::is_trivially_copy_assignable_v<pro::proxy<TrivialFacade>>);
static_assert(std::is_nothrow_move_constructible_v<pro::proxy<TrivialFacade>>);
Expand Down

0 comments on commit 254628b

Please sign in to comment.