Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find_indices (enhancement) #33

Open
gabyx opened this issue Mar 29, 2016 · 0 comments
Open

find_indices (enhancement) #33

gabyx opened this issue Mar 29, 2016 · 0 comments

Comments

@gabyx
Copy link

gabyx commented Mar 29, 2016

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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant