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
22
iterator.hpp
22
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>
|
||||
class indices {
|
||||
public:
|
||||
using value_type = typename index_type<ContainerT>::type;
|
||||
using value_type = std::size_t;
|
||||
|
||||
indices (const ContainerT &_container):
|
||||
m_container (_container)
|
||||
@ -287,7 +269,7 @@ namespace cruft {
|
||||
};
|
||||
|
||||
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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user