diff options
Diffstat (limited to 'src/list/operation/higher/list_index.h')
-rw-r--r-- | src/list/operation/higher/list_index.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/list/operation/higher/list_index.h b/src/list/operation/higher/list_index.h new file mode 100644 index 0000000..bbf43ee --- /dev/null +++ b/src/list/operation/higher/list_index.h @@ -0,0 +1,45 @@ +#ifndef TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_LIST_INDEX_H_ +#define TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_LIST_INDEX_H_ + +#include "operation/math.h" + +namespace tav { + +namespace detail { + +template < + template<typename> class Predicate, + typename List, + typename Index = Size<0> +> +struct index_of_first { + typedef If< + Eval<Predicate<Head<List>>>, + Index, + Eval<index_of_first< + Predicate, + Tail<List>, + Add<Index, Size<1>> + >> + > type; +}; + +template < + template<typename> class Predicate, + typename Index +> +struct index_of_first<Predicate, void, Index> { + typedef void type; +}; + +} + +template < + template<typename> class Predicate, + typename List +> +using ListIndex = Eval<detail::index_of_first<Predicate, List>>; + +} + +#endif // TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_LIST_INDEX_H_ |