cartesian_product<type_list<...>> -- now with edge cases!

Add test cases for zero or one input type_list.
This commit is contained in:
Allison Vacanti
2020-12-31 19:51:18 -05:00
parent b1cbf6cab8
commit 29d7eafc33
2 changed files with 32 additions and 6 deletions

View File

@@ -59,22 +59,27 @@ struct cartesian_product;
template <>
struct cartesian_product<nvbench::type_list<>>
{
using type = nvbench::type_list<>;
{ // If no input type_lists are provided, there's just one output --
// a null type_list:
using type = nvbench::type_list<nvbench::type_list<>>;
};
template <typename... TLTail>
struct cartesian_product<nvbench::type_list<nvbench::type_list<>, TLTail...>>
{
{ // This is a recursion base case -- in practice empty type_lists should
// not be passed into cartesian_product.
using type = nvbench::type_list<>;
};
template <typename T, typename... Ts>
struct cartesian_product<nvbench::type_list<nvbench::type_list<T, Ts...>>>
{
using cur = nvbench::type_list<nvbench::type_list<T>>;
using next = typename detail::cartesian_product<
nvbench::type_list<nvbench::type_list<Ts...>>>::type;
using cur = nvbench::type_list<nvbench::type_list<T>>;
using next =
std::conditional_t<sizeof...(Ts) != 0,
typename detail::cartesian_product<
nvbench::type_list<nvbench::type_list<Ts...>>>::type,
nvbench::type_list<>>;
using type = decltype(detail::concat(cur{}, next{}));
};

View File

@@ -84,6 +84,27 @@ struct test_prepend_each
static_assert(std::is_same_v<nvbench::tl::prepend_each<T, TLs>, Expected>);
};
struct test_empty_cartesian_product
{
using prod = nvbench::tl::cartesian_product<nvbench::type_list<>>;
static_assert(
std::is_same_v<prod, nvbench::type_list<nvbench::type_list<>>>);
};
struct test_single_cartesian_product
{
using prod_1 =
nvbench::tl::cartesian_product<nvbench::type_list<nvbench::type_list<T0>>>;
static_assert(
std::is_same_v<prod_1, nvbench::type_list<nvbench::type_list<T0>>>);
using prod_2 = nvbench::tl::cartesian_product<
nvbench::type_list<nvbench::type_list<T0, T1>>>;
static_assert(std::is_same_v<prod_2,
nvbench::type_list<nvbench::type_list<T0>,
nvbench::type_list<T1>>>);
};
struct test_cartesian_product
{
using U0 = T2;