find_indices (enhancement)
gabyx opened this issue · 0 comments
gabyx commented
I suggest the following handy plural form of find_index
:
namespace details {
template<typename List, std::size_t I>
struct find_ind_state {
using L = List;
static const std::size_t Idx = I;
};
template<typename Type>
struct find_indices {
template<typename State, typename T>
using invoke = find_ind_state<
meta::if_< std::is_same<Type,T> ,
meta::push_back< typename State::L, meta::size_t<State::Idx> >,
typename State::L
>,
State::Idx+1
>;
};
};
/** Returns a list of all indices of types equal to \p T in list \p */
template<typename T, typename List>
using find_indices = typename meta::accumulate< List,
details::find_ind_state< meta::list<> , 0 >,
/* accumulate the index list and the current index of the element*/
details::find_indices<T>
>::L;