From f0e9475dcc653970ccaf656ed1e8318f9b3edafc Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Mon, 21 Apr 2025 15:00:57 -0400 Subject: [PATCH] silly boy --- CMakeLists.txt | 2 +- include/blt/std/variant.h | 116 +++++++++++++++---------------------- libraries/parallel-hashmap | 2 +- 3 files changed, 49 insertions(+), 71 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6159065..cfdc1ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.20) include(cmake/color.cmake) -set(BLT_VERSION 5.4.4) +set(BLT_VERSION 5.4.5) set(BLT_TARGET BLT) diff --git a/include/blt/std/variant.h b/include/blt/std/variant.h index e1428ef..0ea2c87 100644 --- a/include/blt/std/variant.h +++ b/include/blt/std/variant.h @@ -66,99 +66,94 @@ namespace blt using return_type = std::conditional_t, void>; }; - template + template struct passthrough_value { using type = T; using func = Func; - - bool has_value = false; - - explicit passthrough_value(const bool has_value): has_value(has_value) - { - } + constexpr static size_t index = Index; explicit operator bool() const { - return has_value; + return HasValue; } - }; template struct first_invoke_member_func { - constexpr static auto find_func() + template + constexpr static auto find_func(std::index_sequence) { return (... || []() { using Meta = member_func_meta; if constexpr (Meta::can_invoke::value) { - return passthrough_value{true}; + return passthrough_value{}; } - return passthrough_value{false}; + return passthrough_value{}; }()); } - using result = decltype(find_func()); + using result = decltype(find_func(std::index_sequence_for())); using return_type = typename result::type; using func_type = typename result::func; + constexpr static size_t function_index = result::index; }; - - template - struct member_func_detail; - - template - struct member_func_detail + template + struct member_func_detail { - template - using return_type = std::invoke_result_t; + }; - template - using can_invoke = std::is_invocable; + template + struct member_func_detail, std::tuple> + { + using result_types = std::tuple...>; + using base_type = typename decltype(std::get<0>(std::declval))::type; - template - using result_or_void = std::conditional::value, return_type, void>; + template + using get_type = typename T::type; - constexpr static bool all_has_void = std::conjunction_v>...>; + template + using is_base = std::is_same; - using ret_type = std::conditional_t( - std::declval, return_type...>>()))>; + template + using is_base_or_void = std::disjunction, is_base>; - constexpr static bool all_has_ret = std::conjunction_v>...>; - constexpr static bool ret_or_void = std::conjunction_v>, std::is_void>>...>; + template typename Functor, template typename PerType, size_t... Indexes> + constexpr static auto for_each_type(std::index_sequence) + { + return std::declval(std::declval()))>...>>; + } + + constexpr static bool all_has_void = for_each_type(std::index_sequence_for()); + constexpr static bool all_has_ret = for_each_type(std::index_sequence_for()); + constexpr static bool all_has_ret_or_void = for_each_type(std::index_sequence_for()); + + using non_void_types = typename decltype(for_each_type(std::index_sequence_for()))::type; template static constexpr auto make_variant(std::index_sequence) { if constexpr (all_has_void) return; - using tuple_type = filter_void_t; - using variant = variant_t(std::declval()))...>; + using variant = variant_t(std::declval()))...>; return std::declval(); } - using variant_type = decltype(make_variant(std::index_sequence_for{})); - static constexpr auto make_return_type() { if constexpr (all_has_void) return; if constexpr (all_has_ret) - return std::declval(); - if constexpr (ret_or_void) - return std::declval>(); - return std::declval(); + return std::declval(); + if constexpr (all_has_ret_or_void) + return std::declval>(); + return make_variant(std::make_index_sequence>{}); } }; - - template - struct member_func_detail - { - }; } /* @@ -280,9 +275,9 @@ namespace blt * @param visitees user lambdas */ template - constexpr void visit_empty(Visitee&&... visitees) + constexpr auto visit(Visitee&&... visitees) -> decltype(detail::member_func_detail, std::tuple>::make_return_type()) { - std::visit(lambda_visitor{ + return std::visit(lambda_visitor{ std::forward(visitees)..., [](auto) { @@ -302,31 +297,14 @@ namespace blt }); } - template - constexpr auto visit_lambda(Default&& default_lambda, Visitee&&... visitees) -> decltype(auto) - { - return std::visit(lambda_visitor{ - std::forward(visitees)..., - [default_lambda=std::forward(default_lambda)](auto&& value) - { - return std::forward(default_lambda)(std::forward(value)); - } - }); - } - - /** - * Call a set of member functions on the types stored in the variant. If a type has more than one of these functions declared on it, - * the implementation will use the first member function provided. By default, if the stored value doesn't have any of the member functions, - * nothing will happen, if should_throw boolean is true, then the implementation will throw a runtime error. - * @tparam should_throw Controls if the implementation should throw if the type stored in the variant doesn't have any matching member function - * @return Result of calling the member functions. All functions should return the same value, otherwise this won't compile. - */ template constexpr auto call_member(const MemberFuncs... funcs) { static_assert(std::conjunction_v>...>, "Must provide only pointers to member functions!"); - return std::visit([=](auto&& value) + using meta_t = detail::member_func_detail, std::tuple>; + using result_t = decltype(meta_t::make_return_type()); + return std::visit([=](auto&& value) -> result_t { using ValueType = std::decay_t; @@ -340,10 +318,10 @@ namespace blt using ReturnType = std::invoke_result_t; if constexpr (std::is_invocable_v) { - return std::make_optional(((value).*(func))()); + return ((value).*(func))(); } - return std::optional{}; - }(cast_member_ptr>(std::forward(funcs))))); + return std::declval(); + }(cast_member_ptr>(std::forward(funcs))))); }, m_variant); } diff --git a/libraries/parallel-hashmap b/libraries/parallel-hashmap index 8a889d3..d88c5e1 160000 --- a/libraries/parallel-hashmap +++ b/libraries/parallel-hashmap @@ -1 +1 @@ -Subproject commit 8a889d3699b3c09ade435641fb034427f3fd12b6 +Subproject commit d88c5e15079047777b418132ece5879e7c9aaa2b