From e801752956124178cc11f07f72bb389408d863c1 Mon Sep 17 00:00:00 2001 From: Mingxin Wang Date: Wed, 26 Jun 2024 22:54:05 +0800 Subject: [PATCH 1/2] Improve accessibility --- proxy.h | 1056 +++++++++++++----------------- tests/proxy_dispatch_tests.cpp | 278 +++++--- tests/proxy_invocation_tests.cpp | 27 +- tests/proxy_reflection_tests.cpp | 10 - tests/proxy_traits_tests.cpp | 12 + 5 files changed, 636 insertions(+), 747 deletions(-) diff --git a/proxy.h b/proxy.h index 8483c15f..1b0d94ba 100644 --- a/proxy.h +++ b/proxy.h @@ -21,6 +21,12 @@ #error "Proxy requires C++20 attribute no_unique_address" #endif +#if defined(_MSC_VER) && !defined(__clang__) +#define ___PRO_ENFORCE_EBO __declspec(empty_bases) +#else +#define ___PRO_ENFORCE_EBO +#endif // defined(_MSC_VER) && !defined(__clang__) + #define ___PRO_DIRECT_FUNC_IMPL(...) \ noexcept(noexcept(__VA_ARGS__)) requires(requires { __VA_ARGS__; }) \ { return __VA_ARGS__; } @@ -46,10 +52,6 @@ struct conditional_traits { static constexpr bool applicable = A; }; using applicable_traits = conditional_traits; using inapplicable_traits = conditional_traits; -template struct lazy_eval_traits : std::type_identity {}; -template -using lazy_eval_t = typename lazy_eval_traits::type; - enum class qualifier_type { lv, const_lv, rv, const_rv }; template struct add_qualifier_traits; template @@ -251,12 +253,9 @@ struct indirect_overload_traits_impl : applicable_traits { } } }; - struct resolver - { indirect_overload_traits_impl operator()(const std::byte&, Args...); }; template static constexpr bool applicable_ptr = invocable_indirect_dispatch_ptr; - static constexpr bool is_noexcept = NE; }; template struct direct_overload_traits_impl : applicable_traits { @@ -274,14 +273,9 @@ struct direct_overload_traits_impl : applicable_traits { } } }; - struct resolver { - direct_overload_traits_impl operator()( - add_qualifier_t, Args...); - }; template static constexpr bool applicable_ptr = invocable_direct_dispatch_ptr; - static constexpr bool is_noexcept = NE; }; template struct overload_traits @@ -382,8 +376,6 @@ template using composite_meta = recursive_reduction_t, Ms...>; -template -using proxy_accessor = typename T::template accessor>; template consteval bool is_meta_is_direct_well_formed() { if constexpr (requires { { T::is_direct } -> std::same_as; }) { @@ -393,17 +385,6 @@ consteval bool is_meta_is_direct_well_formed() { } return false; } -template -consteval bool is_a11y_well_formed() { - if constexpr (requires { typename proxy_accessor; }) { - return std::is_trivial_v> && - std::is_empty_v> && - !std::is_final_v>; - } else { - return true; - } - return false; -} template struct conv_traits_impl : inapplicable_traits {}; @@ -411,26 +392,17 @@ template requires(sizeof...(Os) > 0u && (overload_traits< C::dispatch_type::is_direct, Os>::applicable && ...)) struct conv_traits_impl : applicable_traits { - private: - struct overload_resolver : overload_traits< - C::dispatch_type::is_direct, Os>::resolver... { - using overload_traits::resolver - ::operator()...; - }; - - public: - using dispatch_type = typename C::dispatch_type; using meta = composite_meta_impl - ::template meta_provider>...>; - template - using matched_overload_traits = std::invoke_result_t< - overload_resolver, add_qualifier_t, Args...>; + ::template meta_provider>...>; + template + using accessor = typename C::dispatch_type + ::template accessor, Os...>; template static constexpr bool applicable_ptr = (overload_traits< C::dispatch_type::is_direct, Os> - ::template applicable_ptr && ...); + ::template applicable_ptr && ...); }; template struct conv_traits : inapplicable_traits {}; template @@ -504,7 +476,7 @@ template