working on meta

v1
Brett 2024-08-12 22:02:54 -04:00
parent 644f426843
commit c7e3accb9d
3 changed files with 153 additions and 54 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.20) cmake_minimum_required(VERSION 3.20)
include(cmake/color.cmake) 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_TEST_VERSION 0.0.1)
set(BLT_TARGET BLT) set(BLT_TARGET BLT)

View File

@ -100,11 +100,23 @@ namespace blt::meta
class has_func_##FUNC : public std::false_type \ class has_func_##FUNC : public std::false_type \
{}; \ {}; \
template<typename T> \ template<typename T> \
class has_func_##FUNC<T, std::void_t<decltype(std::declval<T>().drop(,##__VA_ARGS__))>> : public std::true_type \ class has_func_##FUNC<T, std::void_t<decltype(std::declval<T>().FUNC(,##__VA_ARGS__))>> : public std::true_type \
{}; \ {}; \
template<typename T> \ template<typename T> \
inline constexpr bool has_func_##FUNC##_v = has_func_##FUNC<T>::value; \ inline constexpr bool has_func_##FUNC##_v = has_func_##FUNC<T>::value;
#define BLT_META_MAKE_MEMBER_CHECK(MEMBER)\
template<typename T, typename = void> \
class has_member_##MEMBER : public std::false_type \
{}; \
template<typename T> \
class has_member_##MEMBER<T, std::void_t<decltype(T::MEMBER)>> : public std::true_type \
{}; \
template<typename T> \
inline constexpr bool has_member_##MEMBER##_v = has_member_##MEMBER<T>::value;
} }
#endif //BLT_GP_META_H #endif //BLT_GP_META_H

View File

@ -9,6 +9,7 @@
#define BLT_RANGES_H #define BLT_RANGES_H
#include <blt/std/types.h> #include <blt/std/types.h>
#include <blt/std/meta.h>
#include <type_traits> #include <type_traits>
#include <iterator> #include <iterator>
#include <memory> #include <memory>
@ -19,6 +20,10 @@ namespace blt
{ {
namespace itr namespace itr
{ {
BLT_META_MAKE_MEMBER_CHECK(value_type);
BLT_META_MAKE_MEMBER_CHECK(reference);
template<typename Begin, typename End> template<typename Begin, typename End>
class itr_container class itr_container
{ {
@ -41,64 +46,53 @@ namespace blt
End end_; End end_;
}; };
template<typename TYPE_ITR, bool is_ptr = std::is_pointer_v<TYPE_ITR>> template<typename T>
class iterator; struct value_type_helper
{
template<typename Subs>
inline static constexpr auto test() -> decltype(Subs::value_type)
{
return std::declval<Subs::value_type>();
}
template<typename>
inline static constexpr auto test() -> decltype(std::remove_pointer_t<T>())
{
return std::declval<std::remove_pointer_t<T>>();
}
};
template<typename T>
struct reference_type_helper
{
template<typename Subs, std::enable_if_t<has_member_reference_v<Subs>, bool> = true>
inline static constexpr auto test() -> typename Subs::reference
{
return std::declval<typename Subs::reference>();
}
template<typename>
inline static constexpr auto test() -> decltype(std::remove_cv_t<std::remove_reference_t<std::remove_pointer_t<T>>>())&
{
return std::declval<std::remove_pointer_t<T>&>();
}
};
template<typename T>
using value_type_t = decltype(value_type_helper<T>::template test<T>());
template<typename T>
using reference_t = decltype(reference_type_helper<T>::template test<T>());
template<typename TYPE_ITR> template<typename TYPE_ITR>
class iterator<TYPE_ITR, false> class iterator
{ {
public: public:
using iterator_category = std::input_iterator_tag; using iterator_category = std::input_iterator_tag;
using value_type = typename TYPE_ITR::value_type; using value_type = value_type_t<TYPE_ITR>;
using difference_type = typename TYPE_ITR::difference_type; using difference_type = typename TYPE_ITR::difference_type;
using pointer = typename TYPE_ITR::pointer; using pointer = typename TYPE_ITR::pointer;
using reference = typename TYPE_ITR::reference; using reference = reference_t<TYPE_ITR>;
using const_reference = const typename TYPE_ITR::reference; using const_reference = const reference_t<TYPE_ITR>;
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<blt::size_t, const_reference> operator*() const
{
return {index, *current};
};
std::pair<blt::size_t, reference> operator*()
{
return {index, *current};
};
};
template<typename TYPE_ITR>
class iterator<TYPE_ITR, true>
{
public:
using iterator_category = std::input_iterator_tag;
using value_type = std::remove_pointer_t<TYPE_ITR>;
using difference_type = std::ptrdiff_t;
using pointer = TYPE_ITR;
using reference = std::remove_pointer_t<TYPE_ITR>&;
using const_reference = const std::remove_pointer_t<TYPE_ITR>&;
private: private:
blt::size_t index = 0; blt::size_t index = 0;
TYPE_ITR current; TYPE_ITR current;
@ -133,6 +127,99 @@ namespace blt
return {index, *current}; return {index, *current};
}; };
}; };
// template<typename TYPE_ITR, bool is_ptr = std::is_pointer_v<TYPE_ITR>>
// class iterator;
//
// template<typename TYPE_ITR>
// class iterator<TYPE_ITR, false>
// {
// 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<blt::size_t, const_reference> operator*() const
// {
// return {index, *current};
// };
//
// std::pair<blt::size_t, reference> operator*()
// {
// return {index, *current};
// };
// };
//
// template<typename TYPE_ITR>
// class iterator<TYPE_ITR, true>
// {
// public:
// using iterator_category = std::input_iterator_tag;
// using value_type = std::remove_pointer_t<TYPE_ITR>;
// using difference_type = std::ptrdiff_t;
// using pointer = TYPE_ITR;
// using reference = std::remove_pointer_t<TYPE_ITR>&;
// using const_reference = const std::remove_pointer_t<TYPE_ITR>&;
// 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<blt::size_t, const_reference> operator*() const
// {
// return {index, *current};
// };
//
// std::pair<blt::size_t, reference> operator*()
// {
// return {index, *current};
// };
// };
} }
template<typename TYPE_ITR> template<typename TYPE_ITR>