From e48fdf0c86d089db39e4c80918d4e0a7344783a5 Mon Sep 17 00:00:00 2001 From: Brett Date: Fri, 28 Feb 2025 02:29:30 -0500 Subject: [PATCH] flatten partially works --- CMakeLists.txt | 2 +- include/blt/iterator/enumerate.h | 11 ------ include/blt/iterator/flatten.h | 57 ++++++++++++++------------------ include/blt/iterator/fwddecl.h | 4 ++- include/blt/meta/type_traits.h | 26 ++++++++++++--- 5 files changed, 50 insertions(+), 50 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 574560d..dcdc9e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.20) include(cmake/color.cmake) -set(BLT_VERSION 4.0.33) +set(BLT_VERSION 4.0.34) set(BLT_TARGET BLT) diff --git a/include/blt/iterator/enumerate.h b/include/blt/iterator/enumerate.h index 3dbc9af..2f63cc2 100644 --- a/include/blt/iterator/enumerate.h +++ b/include/blt/iterator/enumerate.h @@ -25,17 +25,6 @@ namespace blt { namespace iterator { - /** - * struct which is returned by the enumerator. - * @tparam T type to store. - */ - template - struct enumerate_item - { - const size_t index; - T value; - }; - template class enumerate_wrapper : public passthrough_wrapper> { diff --git a/include/blt/iterator/flatten.h b/include/blt/iterator/flatten.h index 75577dc..79fdca3 100644 --- a/include/blt/iterator/flatten.h +++ b/include/blt/iterator/flatten.h @@ -20,43 +20,34 @@ #define BLT_ITERATOR_FLATTEN_H #include +#include #include namespace blt::iterator { namespace detail { - template - struct make_tuple + template + static auto flatten(Tuple&& tuple) -> decltype(auto) { - using type = std::tuple; - - static auto convert(T& f) + using Decay = std::decay_t; + if constexpr (meta::is_tuple_v || meta::is_pair_v) { - return std::forward_as_tuple(f); - } - - static auto convert(T&& f) + return std::apply([](auto&&... args) + { + return std::tuple_cat(flatten(std::forward(args))...); + }, std::forward(tuple)); + } else { - return std::forward_as_tuple(f); + if constexpr (std::is_lvalue_reference_v) + { + return std::forward_as_tuple(std::forward(tuple)); + } else + { + return std::make_tuple(std::forward(tuple)); + } } - }; - - template - struct make_tuple> - { - using type = std::tuple; - - static std::tuple& convert(std::tuple& lvalue) - { - return lvalue; - } - - static std::tuple&& convert(std::tuple&& rvalue) - { - return rvalue; - } - }; + } } template @@ -64,19 +55,19 @@ namespace blt::iterator { public: using iterator_category = typename std::iterator_traits::iterator_category; - // using value_type = std::invoke_result_t>; + using value_type = std::remove_reference_t()))>; using difference_type = ptrdiff_t; - // using pointer = value_type; - // using reference = value_type; + using pointer = value_type*; + using reference = value_type&; explicit flatten_wrapper(Iter iter): - deref_only_wrapper>(std::move(iter)) + deref_only_wrapper(std::move(iter)) { } - reference operator*() const + auto operator*() const -> decltype(auto) { - return func(*this->iter); + return detail::flatten(*this->iter); } }; } diff --git a/include/blt/iterator/fwddecl.h b/include/blt/iterator/fwddecl.h index 612ce36..6fcf5b3 100644 --- a/include/blt/iterator/fwddecl.h +++ b/include/blt/iterator/fwddecl.h @@ -19,6 +19,8 @@ #ifndef BLT_ITERATOR_FWDDECL_H #define BLT_ITERATOR_FWDDECL_H +#include + namespace blt { template @@ -33,7 +35,7 @@ namespace blt struct iterator_pair; template - struct enumerate_item; + using enumerate_item = std::pair; template class enumerate_wrapper; diff --git a/include/blt/meta/type_traits.h b/include/blt/meta/type_traits.h index 5be8c28..645ebd6 100644 --- a/include/blt/meta/type_traits.h +++ b/include/blt/meta/type_traits.h @@ -24,6 +24,15 @@ namespace blt::meta { + namespace detail + { + template + void empty_apply_function(Args...) + { + + } + } + template using remove_cvref_t = std::remove_volatile_t>>; @@ -50,15 +59,24 @@ namespace blt::meta { }; - template + template static constexpr bool is_tuple_v = is_tuple::value; - template + template static constexpr bool is_pair_v = is_pair::value; - template - static constexpr bool is_tuple_like_v = is_tuple_v || is_pair_v; + template + struct is_tuple_like : std::false_type + { + }; + template + struct is_tuple_like, std::tuple_element<0, T>>> : std::true_type + { + }; + + template + inline constexpr bool is_tuple_like_v = is_tuple_like::value; } #endif // BLT_META_TYPE_TRAITS_H