meow
parent
c7e3accb9d
commit
6f06647a21
|
@ -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.31)
|
set(BLT_VERSION 0.18.32)
|
||||||
set(BLT_TEST_VERSION 0.0.1)
|
set(BLT_TEST_VERSION 0.0.1)
|
||||||
|
|
||||||
set(BLT_TARGET BLT)
|
set(BLT_TARGET BLT)
|
||||||
|
|
|
@ -95,6 +95,100 @@ namespace blt::meta
|
||||||
template<class T>
|
template<class T>
|
||||||
inline constexpr bool is_streamable_v = is_streamable<T>::value;
|
inline constexpr bool is_streamable_v = is_streamable<T>::value;
|
||||||
|
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
template<typename Or>
|
||||||
|
struct value_type_helper
|
||||||
|
{
|
||||||
|
template<typename Subs>
|
||||||
|
inline static constexpr auto get(int) -> typename Subs::value_type
|
||||||
|
{
|
||||||
|
return std::declval<Subs::value_type>();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename>
|
||||||
|
inline static constexpr Or get(...)
|
||||||
|
{
|
||||||
|
return std::declval<Or>();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename Or>
|
||||||
|
struct reference_type_helper
|
||||||
|
{
|
||||||
|
template<typename Subs>
|
||||||
|
inline static constexpr auto get(int) -> typename Subs::reference
|
||||||
|
{
|
||||||
|
return std::declval<typename Subs::reference>();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename>
|
||||||
|
inline static constexpr Or get(...)
|
||||||
|
{
|
||||||
|
return std::declval<Or>();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename Or>
|
||||||
|
struct const_reference_type_helper
|
||||||
|
{
|
||||||
|
template<typename Subs>
|
||||||
|
inline static constexpr auto get(int) -> typename Subs::const_reference
|
||||||
|
{
|
||||||
|
return std::declval<typename Subs::const_reference>();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename>
|
||||||
|
inline static constexpr Or get(...)
|
||||||
|
{
|
||||||
|
return std::declval<Or>();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename Or>
|
||||||
|
struct pointer_type_helper
|
||||||
|
{
|
||||||
|
template<typename Subs>
|
||||||
|
inline static constexpr auto get(int) -> typename Subs::pointer
|
||||||
|
{
|
||||||
|
return std::declval<typename Subs::pointer>();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename>
|
||||||
|
inline static constexpr Or get(...)
|
||||||
|
{
|
||||||
|
return std::declval<Or>();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename Or>
|
||||||
|
struct difference_type_helper
|
||||||
|
{
|
||||||
|
template<typename Subs>
|
||||||
|
inline static constexpr auto get(int) -> typename Subs::difference_type
|
||||||
|
{
|
||||||
|
return std::declval<typename Subs::difference_type>();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename>
|
||||||
|
inline static constexpr Or get(...)
|
||||||
|
{
|
||||||
|
return std::declval<Or>();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, typename Or>
|
||||||
|
using value_type_t = decltype(detail::value_type_helper<Or>::template get<T>(0));
|
||||||
|
template<typename T, typename Or>
|
||||||
|
using difference_t = decltype(detail::difference_type_helper<Or>::template get<T>(0));
|
||||||
|
template<typename T, typename Or>
|
||||||
|
using pointer_t = decltype(detail::pointer_type_helper<Or>::template get<T>(0));
|
||||||
|
template<typename T, typename Or>
|
||||||
|
using reference_t = decltype(detail::reference_type_helper<Or>::template get<T>(0));
|
||||||
|
template<typename T, typename Or>
|
||||||
|
using const_reference_t = decltype(detail::const_reference_type_helper<Or>::template get<T>(0));
|
||||||
|
|
||||||
#define BLT_META_MAKE_FUNCTION_CHECK(FUNC, ...)\
|
#define BLT_META_MAKE_FUNCTION_CHECK(FUNC, ...)\
|
||||||
template<typename T, typename = void> \
|
template<typename T, typename = void> \
|
||||||
class has_func_##FUNC : public std::false_type \
|
class has_func_##FUNC : public std::false_type \
|
||||||
|
|
|
@ -20,9 +20,6 @@ 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
|
||||||
|
@ -46,60 +43,39 @@ namespace blt
|
||||||
End end_;
|
End end_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename TYPE_ITR>
|
||||||
struct value_type_helper
|
class iterator_base
|
||||||
{
|
{
|
||||||
template<typename Subs>
|
public:
|
||||||
inline static constexpr auto test() -> decltype(Subs::value_type)
|
using value_type = blt::meta::value_type_t<TYPE_ITR, std::remove_pointer_t<TYPE_ITR>>;
|
||||||
{
|
using difference_type = blt::meta::difference_t<TYPE_ITR, std::ptrdiff_t>;
|
||||||
return std::declval<Subs::value_type>();
|
using pointer = blt::meta::pointer_t<TYPE_ITR, TYPE_ITR>;
|
||||||
}
|
using reference = blt::meta::reference_t<TYPE_ITR, std::remove_pointer_t<TYPE_ITR>&>;
|
||||||
|
using const_reference = blt::meta::const_reference_t<TYPE_ITR, const std::remove_pointer_t<TYPE_ITR>&>;
|
||||||
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
|
class iterator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using iterator_category = std::input_iterator_tag;
|
using iterator_category = std::input_iterator_tag;
|
||||||
using value_type = value_type_t<TYPE_ITR>;
|
using value_type = typename iterator_base<TYPE_ITR>::value_type;
|
||||||
using difference_type = typename TYPE_ITR::difference_type;
|
using difference_type = typename iterator_base<TYPE_ITR>::difference_type;
|
||||||
using pointer = typename TYPE_ITR::pointer;
|
using pointer = typename iterator_base<TYPE_ITR>::pointer;
|
||||||
using reference = reference_t<TYPE_ITR>;
|
using reference = typename iterator_base<TYPE_ITR>::reference;
|
||||||
using const_reference = const reference_t<TYPE_ITR>;
|
using const_reference = typename iterator_base<TYPE_ITR>::const_reference;
|
||||||
private:
|
private:
|
||||||
blt::size_t index = 0;
|
blt::size_t index;
|
||||||
TYPE_ITR current;
|
TYPE_ITR current;
|
||||||
public:
|
public:
|
||||||
explicit iterator(TYPE_ITR current): current(std::move(current))
|
explicit iterator(TYPE_ITR current, blt::size_t index): index(index), current(std::move(current))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
auto iter()
|
||||||
|
{
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
|
||||||
iterator& operator++()
|
iterator& operator++()
|
||||||
{
|
{
|
||||||
++index;
|
++index;
|
||||||
|
@ -128,105 +104,66 @@ namespace blt
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// template<typename TYPE_ITR, bool is_ptr = std::is_pointer_v<TYPE_ITR>>
|
template<typename TYPE_ITR>
|
||||||
// class iterator;
|
class reverse_iterator
|
||||||
//
|
{
|
||||||
// template<typename TYPE_ITR>
|
public:
|
||||||
// class iterator<TYPE_ITR, false>
|
using iterator_category = std::input_iterator_tag;
|
||||||
// {
|
using value_type = typename iterator_base<TYPE_ITR>::value_type;
|
||||||
// public:
|
using difference_type = typename iterator_base<TYPE_ITR>::difference_type;
|
||||||
// using iterator_category = std::input_iterator_tag;
|
using pointer = typename iterator_base<TYPE_ITR>::pointer;
|
||||||
// using value_type = typename TYPE_ITR::value_type;
|
using reference = typename iterator_base<TYPE_ITR>::reference;
|
||||||
// using difference_type = typename TYPE_ITR::difference_type;
|
using const_reference = typename iterator_base<TYPE_ITR>::const_reference;
|
||||||
// using pointer = typename TYPE_ITR::pointer;
|
private:
|
||||||
// using reference = typename TYPE_ITR::reference;
|
blt::size_t index;
|
||||||
// using const_reference = const typename TYPE_ITR::reference;
|
TYPE_ITR current;
|
||||||
// private:
|
public:
|
||||||
// blt::size_t index = 0;
|
explicit reverse_iterator(TYPE_ITR current, blt::size_t index): index(index), current(std::move(current))
|
||||||
// TYPE_ITR current;
|
{}
|
||||||
// public:
|
|
||||||
// explicit iterator(TYPE_ITR current): current(std::move(current))
|
auto iter()
|
||||||
// {}
|
{
|
||||||
//
|
return 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>
|
reverse_iterator& operator++()
|
||||||
|
{
|
||||||
|
--index;
|
||||||
|
--current;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(reverse_iterator other) const
|
||||||
|
{
|
||||||
|
return current == other.current;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(reverse_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> typename iterator = itr::iterator>
|
||||||
class enumerator
|
class enumerator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit enumerator(TYPE_ITR begin, TYPE_ITR end): begin_(std::move(begin)), end_(std::move(end))
|
explicit enumerator(TYPE_ITR begin, TYPE_ITR end): begin_(std::move(begin), 0), end_(std::move(end), 0)
|
||||||
|
{}
|
||||||
|
|
||||||
|
explicit enumerator(TYPE_ITR begin, TYPE_ITR end, blt::size_t i_begin, blt::size_t i_end):
|
||||||
|
begin_(std::move(begin), i_begin), end_(std::move(end), i_end)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
itr::iterator<TYPE_ITR> begin()
|
itr::iterator<TYPE_ITR> begin()
|
||||||
|
@ -240,8 +177,8 @@ namespace blt
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
itr::iterator<TYPE_ITR> begin_;
|
iterator<TYPE_ITR> begin_;
|
||||||
itr::iterator<TYPE_ITR> end_;
|
iterator<TYPE_ITR> end_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
Loading…
Reference in New Issue