12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- #include "simple/support/meta/find.hpp"
- #include "simple/support/meta/bind.hpp"
- #include "simple/support/meta/list.hpp"
- #include <type_traits>
- using namespace simple::support;
- template <size_t i>
- using size_constant = std::integral_constant<size_t, i>;
- // find double counting floats on the way
- template <typename count, typename T>
- struct count_float_until_double
- {
- static constexpr bool value = std::is_same_v<T, double>;
- using binding = size_constant<count{} + std::is_same_v<T,float>>;
- };
- // find double counting floats on the way
- template <typename T, typename count>
- struct count_float_until_double2
- {
- static constexpr bool value = std::is_same_v<T, double>;
- using binding = size_constant<count{} + std::is_same_v<T,float>>;
- };
- int main()
- {
- static_assert(meta::find_v<bool,
- meta::list<char, int, bool, double>>
- == 2
- );
- static_assert(meta::find_v<short,
- meta::list<char, int, bool, double>>
- == 4
- );
- static_assert(meta::find_if_v<std::is_floating_point,
- meta::list<char, int, bool, double>>
- == 3
- );
- static_assert(meta::find_if_v<std::is_array,
- meta::list<char, int, bool, double>>
- == 4
- );
- static_assert(std::is_same_v<
- meta::find_if_t<std::is_floating_point,
- meta::list<char, bool, double, int>>,
- double
- >);
- using found = meta::find_t
- <
- meta::bind<count_float_until_double, size_constant<0>>,
- meta::list<char, float, bool, float, double, int, float>
- >;
- // found double
- static_assert(std::is_same_v<found::type, double>);
- // at index 4
- static_assert(found::value == 4);
- // counted 2 floats
- static_assert(found::functor::binding{} == 2);
- using found2 = meta::find_t
- <
- meta::bind_after<count_float_until_double2, size_constant<0>>,
- meta::list<char, float, bool, float, double, int, float>
- >;
- // found double
- static_assert(std::is_same_v<found2::type, double>);
- // at index 4
- static_assert(found2::value == 4);
- // counted 2 floats
- static_assert(found2::functor::binding{} == 2);
- return 0;
- }
|