|
| 1 | +#include <stdx/meta.hpp> |
| 2 | + |
| 3 | +#include <boost/mp11/algorithm.hpp> |
| 4 | +#include <catch2/catch_test_macros.hpp> |
| 5 | + |
| 6 | +namespace { |
| 7 | +using list_t = boost::mp11::mp_iota_c<5>; |
| 8 | +template <typename T> using is_even = std::bool_constant<T::value % 2 == 0>; |
| 9 | +} // namespace |
| 10 | + |
| 11 | +TEST_CASE("filtered_index (items that pass the predicate)", "[meta]") { |
| 12 | + STATIC_CHECK( |
| 13 | + std::same_as<stdx::mp::filtered_index<list_t, is_even, |
| 14 | + boost::mp11::mp_size_t<0>>, |
| 15 | + boost::mp11::mp_size_t<0>>); |
| 16 | + STATIC_CHECK( |
| 17 | + std::same_as<stdx::mp::filtered_index<list_t, is_even, |
| 18 | + boost::mp11::mp_size_t<2>>, |
| 19 | + boost::mp11::mp_size_t<1>>); |
| 20 | + STATIC_CHECK( |
| 21 | + std::same_as<stdx::mp::filtered_index<list_t, is_even, |
| 22 | + boost::mp11::mp_size_t<4>>, |
| 23 | + boost::mp11::mp_size_t<2>>); |
| 24 | +} |
| 25 | + |
| 26 | +TEST_CASE("filtered_index (items that fail the predicate)", "[meta]") { |
| 27 | + STATIC_CHECK( |
| 28 | + std::same_as<stdx::mp::filtered_index<list_t, is_even, |
| 29 | + boost::mp11::mp_size_t<1>>, |
| 30 | + boost::mp11::mp_size_t<3>>); |
| 31 | + STATIC_CHECK( |
| 32 | + std::same_as<stdx::mp::filtered_index<list_t, is_even, |
| 33 | + boost::mp11::mp_size_t<3>>, |
| 34 | + boost::mp11::mp_size_t<3>>); |
| 35 | +} |
| 36 | + |
| 37 | +TEST_CASE("filtered_index_c", "[meta]") { |
| 38 | + STATIC_CHECK(std::same_as<stdx::mp::filtered_index_c<list_t, is_even, 0>, |
| 39 | + boost::mp11::mp_size_t<0>>); |
| 40 | + STATIC_CHECK(std::same_as<stdx::mp::filtered_index_c<list_t, is_even, 2>, |
| 41 | + boost::mp11::mp_size_t<1>>); |
| 42 | + STATIC_CHECK(std::same_as<stdx::mp::filtered_index_c<list_t, is_even, 4>, |
| 43 | + boost::mp11::mp_size_t<2>>); |
| 44 | +} |
0 commit comments