From c7e3accb9d9929b6bf7451d64f0b845c0cf4262c Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Mon, 12 Aug 2024 22:02:54 -0400 Subject: [PATCH] working on meta --- CMakeLists.txt | 2 +- include/blt/std/meta.h | 16 +++- include/blt/std/ranges.h | 189 ++++++++++++++++++++++++++++----------- 3 files changed, 153 insertions(+), 54 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b582c8..d546358 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.20) include(cmake/color.cmake) -set(BLT_VERSION 0.18.30) +set(BLT_VERSION 0.18.31) set(BLT_TEST_VERSION 0.0.1) set(BLT_TARGET BLT) diff --git a/include/blt/std/meta.h b/include/blt/std/meta.h index d5c4113..6872483 100644 --- a/include/blt/std/meta.h +++ b/include/blt/std/meta.h @@ -100,11 +100,23 @@ namespace blt::meta class has_func_##FUNC : public std::false_type \ {}; \ template \ - class has_func_##FUNC().drop(,##__VA_ARGS__))>> : public std::true_type \ + class has_func_##FUNC().FUNC(,##__VA_ARGS__))>> : public std::true_type \ {}; \ template \ - inline constexpr bool has_func_##FUNC##_v = has_func_##FUNC::value; \ + inline constexpr bool has_func_##FUNC##_v = has_func_##FUNC::value; + +#define BLT_META_MAKE_MEMBER_CHECK(MEMBER)\ + template \ + class has_member_##MEMBER : public std::false_type \ + {}; \ + template \ + class has_member_##MEMBER> : public std::true_type \ + {}; \ + template \ + inline constexpr bool has_member_##MEMBER##_v = has_member_##MEMBER::value; + + } #endif //BLT_GP_META_H diff --git a/include/blt/std/ranges.h b/include/blt/std/ranges.h index 0d53c0d..cb4c7af 100644 --- a/include/blt/std/ranges.h +++ b/include/blt/std/ranges.h @@ -9,6 +9,7 @@ #define BLT_RANGES_H #include +#include #include #include #include @@ -19,6 +20,10 @@ namespace blt { namespace itr { + BLT_META_MAKE_MEMBER_CHECK(value_type); + + BLT_META_MAKE_MEMBER_CHECK(reference); + template class itr_container { @@ -41,64 +46,53 @@ namespace blt End end_; }; - template> - class iterator; + template + struct value_type_helper + { + template + inline static constexpr auto test() -> decltype(Subs::value_type) + { + return std::declval(); + } + + template + inline static constexpr auto test() -> decltype(std::remove_pointer_t()) + { + return std::declval>(); + } + }; + + template + struct reference_type_helper + { + template, bool> = true> + inline static constexpr auto test() -> typename Subs::reference + { + return std::declval(); + } + + template + inline static constexpr auto test() -> decltype(std::remove_cv_t>>())& + { + return std::declval&>(); + } + }; + + template + using value_type_t = decltype(value_type_helper::template test()); + template + using reference_t = decltype(reference_type_helper::template test()); template - class iterator + class iterator { public: using iterator_category = std::input_iterator_tag; - using value_type = typename TYPE_ITR::value_type; + using value_type = value_type_t; using difference_type = typename TYPE_ITR::difference_type; using pointer = typename TYPE_ITR::pointer; - using reference = typename TYPE_ITR::reference; - using const_reference = const typename TYPE_ITR::reference; - private: - blt::size_t index = 0; - TYPE_ITR current; - public: - explicit iterator(TYPE_ITR current): current(std::move(current)) - {} - - iterator& operator++() - { - ++index; - ++current; - return *this; - } - - bool operator==(iterator other) const - { - return current == other.current; - } - - bool operator!=(iterator other) const - { - return current != other.current; - } - - std::pair operator*() const - { - return {index, *current}; - }; - - std::pair operator*() - { - return {index, *current}; - }; - }; - - template - class iterator - { - public: - using iterator_category = std::input_iterator_tag; - using value_type = std::remove_pointer_t; - using difference_type = std::ptrdiff_t; - using pointer = TYPE_ITR; - using reference = std::remove_pointer_t&; - using const_reference = const std::remove_pointer_t&; + using reference = reference_t; + using const_reference = const reference_t; private: blt::size_t index = 0; TYPE_ITR current; @@ -133,6 +127,99 @@ namespace blt return {index, *current}; }; }; + +// template> +// class iterator; +// +// template +// class iterator +// { +// public: +// using iterator_category = std::input_iterator_tag; +// using value_type = typename TYPE_ITR::value_type; +// using difference_type = typename TYPE_ITR::difference_type; +// using pointer = typename TYPE_ITR::pointer; +// using reference = typename TYPE_ITR::reference; +// using const_reference = const typename TYPE_ITR::reference; +// private: +// blt::size_t index = 0; +// TYPE_ITR current; +// public: +// explicit iterator(TYPE_ITR current): current(std::move(current)) +// {} +// +// iterator& operator++() +// { +// ++index; +// ++current; +// return *this; +// } +// +// bool operator==(iterator other) const +// { +// return current == other.current; +// } +// +// bool operator!=(iterator other) const +// { +// return current != other.current; +// } +// +// std::pair operator*() const +// { +// return {index, *current}; +// }; +// +// std::pair operator*() +// { +// return {index, *current}; +// }; +// }; +// +// template +// class iterator +// { +// public: +// using iterator_category = std::input_iterator_tag; +// using value_type = std::remove_pointer_t; +// using difference_type = std::ptrdiff_t; +// using pointer = TYPE_ITR; +// using reference = std::remove_pointer_t&; +// using const_reference = const std::remove_pointer_t&; +// private: +// blt::size_t index = 0; +// TYPE_ITR current; +// public: +// explicit iterator(TYPE_ITR current): current(std::move(current)) +// {} +// +// iterator& operator++() +// { +// ++index; +// ++current; +// return *this; +// } +// +// bool operator==(iterator other) const +// { +// return current == other.current; +// } +// +// bool operator!=(iterator other) const +// { +// return current != other.current; +// } +// +// std::pair operator*() const +// { +// return {index, *current}; +// }; +// +// std::pair operator*() +// { +// return {index, *current}; +// }; +// }; } template