iterator: remove index_type trait
This was used primarily for iteration over map-like objects but it never turned out to be terrifically robust, and encouraged users to either conflate index types or to ham-fist the conversions. It's better to be slightly less ergonomic and reliable than to be more ergonomic and introduce the possibility for errors.
This commit is contained in:
parent
6dede936bd
commit
06d7d2840d
24
iterator.hpp
24
iterator.hpp
@ -221,29 +221,11 @@ namespace cruft {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
/// a trait that stores a type suitable for indexing a container
|
|
||||||
template <typename, typename = std::void_t<>>
|
|
||||||
struct index_type { using type = std::size_t; };
|
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
template <typename ContainerT>
|
|
||||||
struct index_type<
|
|
||||||
ContainerT,
|
|
||||||
std::void_t<
|
|
||||||
typename ContainerT::index_t
|
|
||||||
>
|
|
||||||
> {
|
|
||||||
using type = typename ContainerT::index_t;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
template <typename ContainerT>
|
template <typename ContainerT>
|
||||||
class indices {
|
class indices {
|
||||||
public:
|
public:
|
||||||
using value_type = typename index_type<ContainerT>::type;
|
using value_type = std::size_t;
|
||||||
|
|
||||||
indices (const ContainerT &_container):
|
indices (const ContainerT &_container):
|
||||||
m_container (_container)
|
m_container (_container)
|
||||||
@ -286,8 +268,8 @@ namespace cruft {
|
|||||||
value_type m_index;
|
value_type m_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
iterator begin (void) const { return iterator { value_type {0} }; }
|
iterator begin (void) const { return iterator { value_type {0} }; }
|
||||||
iterator end (void) const { return iterator { value_type (m_container.size ()) }; }
|
iterator end (void) const { return iterator { m_container.size () }; }
|
||||||
|
|
||||||
constexpr auto size (void) const noexcept
|
constexpr auto size (void) const noexcept
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user