working on meta
parent
644f426843
commit
c7e3accb9d
|
@ -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)
|
||||
|
|
|
@ -100,10 +100,22 @@ namespace blt::meta
|
|||
class has_func_##FUNC : public std::false_type \
|
||||
{}; \
|
||||
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> \
|
||||
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;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#define BLT_RANGES_H
|
||||
|
||||
#include <blt/std/types.h>
|
||||
#include <blt/std/meta.h>
|
||||
#include <type_traits>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
|
@ -19,6 +20,10 @@ namespace blt
|
|||
{
|
||||
namespace itr
|
||||
{
|
||||
BLT_META_MAKE_MEMBER_CHECK(value_type);
|
||||
|
||||
BLT_META_MAKE_MEMBER_CHECK(reference);
|
||||
|
||||
template<typename Begin, typename End>
|
||||
class itr_container
|
||||
{
|
||||
|
@ -41,19 +46,53 @@ namespace blt
|
|||
End end_;
|
||||
};
|
||||
|
||||
template<typename TYPE_ITR, bool is_ptr = std::is_pointer_v<TYPE_ITR>>
|
||||
class iterator;
|
||||
template<typename T>
|
||||
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>
|
||||
class iterator<TYPE_ITR, false>
|
||||
class iterator
|
||||
{
|
||||
public:
|
||||
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 pointer = typename TYPE_ITR::pointer;
|
||||
using reference = typename TYPE_ITR::reference;
|
||||
using const_reference = const typename TYPE_ITR::reference;
|
||||
using reference = reference_t<TYPE_ITR>;
|
||||
using const_reference = const reference_t<TYPE_ITR>;
|
||||
private:
|
||||
blt::size_t index = 0;
|
||||
TYPE_ITR current;
|
||||
|
@ -89,50 +128,98 @@ namespace blt
|
|||
};
|
||||
};
|
||||
|
||||
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, 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>
|
||||
|
|
Loading…
Reference in New Issue