#ifndef V8_BASE_TEMPLATE_META_PROGRAMMING_ALGORITHM_H_
#define V8_BASE_TEMPLATE_META_PROGRAMMING_ALGORITHM_H_
#include <type_traits>
#include "src/base/template-meta-programming/list.h"
namespace v8::base::tmp {
namespace detail {
template <template <typename> typename F, typename List>
struct map_impl;
template <template <typename> typename F, typename... Ts>
struct map_impl<F, list<Ts...>> {
using type = list<typename F<Ts>::type...>;
};
template <typename List, typename T, int NotFoundIndex, int I>
struct find_first_impl;
find_first_impl<list<Head, Tail...>, T, NotFoundIndex, I>;
find_first_impl<list<T, Tail...>, T, NotFoundIndex, I>;
find_first_impl<list<>, T, NotFoundIndex, I>;
template <typename List, template <typename, typename> typename Cmp>
struct all_equal_impl;
template <typename Head, typename... Tail,
template <typename, typename> typename Cmp>
struct all_equal_impl<list<Head, Tail...>, Cmp>
: std::bool_constant<(Cmp<Head, Tail>::value && ...)> {};
}
template <template <typename> typename F, typename List>
struct map : detail::map_impl<F, List> { … };
template <template <typename> typename F, typename List>
using map_t = typename map<F, List>::type;
template <typename List, typename T, int NotFoundIndex = -1>
struct find_first : detail::find_first_impl<List, T, NotFoundIndex, 0> { … };
find_first_v;
template <typename List, typename T>
struct contains : std::bool_constant<find_first<List, T, -1>::value != -1> { … };
contains_v;
template <typename List,
template <typename, typename> typename Cmp = std::is_same>
struct all_equal : detail::all_equal_impl<List, Cmp> { … };
all_equal_v = all_equal<List, Cmp>::value;
}
#endif