Add nvbench::tl::size.

This commit is contained in:
Allison Vacanti
2020-12-22 15:09:40 -05:00
parent 9b17a991fc
commit fb10be7e72
3 changed files with 41 additions and 3 deletions

View File

@@ -15,6 +15,10 @@ namespace tl
namespace detail
{
template <typename... Ts>
auto size(nvbench::type_list<Ts...>)
-> std::integral_constant<std::size_t, sizeof...(Ts)>;
template <std::size_t I, typename... Ts>
auto get(nvbench::type_list<Ts...>)
-> std::tuple_element_t<I, std::tuple<Ts...>>;

View File

@@ -16,7 +16,18 @@ namespace tl
{
/**
* Get the TypeList entry at the specified index.
* Get the size of a type_list as a `std::integral_constant<size_t, N>`.
*
* ```c++
* using TL = nvbench::type_list<T0, T1, T2, T3, T4>;
* static_assert(nvbench::tl::size<TL>::value == 5);
* ```
*/
template <typename TypeList>
using size = decltype(detail::size(TypeList{}));
/**
* Get the type at the specified index of a type_list.
*
* ```c++
* using TL = nvbench::type_list<T0, T1, T2, T3, T4>;
@@ -85,8 +96,8 @@ using prepend_each = typename detail::prepend_each<T, TypeLists>::type;
* static_assert(std::is_same_v<bench::tl::cartesian_product<TLs>, CartProd>);
* ```
*/
template <typename TLs>
using cartesian_product = typename detail::cartesian_product<TLs>::type;
template <typename TypeLists>
using cartesian_product = typename detail::cartesian_product<TypeLists>::type;
} // namespace tl

View File

@@ -1,5 +1,7 @@
#include <nvbench/type_list.cuh>
#include <nvbench/type_strings.cuh>
#include <cstdint>
#include <type_traits>
@@ -13,6 +15,27 @@ using T5 = std::integral_constant<std::size_t, 5>;
using T6 = std::integral_constant<std::size_t, 6>;
using T7 = std::integral_constant<std::size_t, 7>;
NVBENCH_DECLARE_TYPE_STRINGS(T0, "T0", "T0");
NVBENCH_DECLARE_TYPE_STRINGS(T1, "T1", "T1");
NVBENCH_DECLARE_TYPE_STRINGS(T2, "T2", "T2");
NVBENCH_DECLARE_TYPE_STRINGS(T3, "T3", "T3");
NVBENCH_DECLARE_TYPE_STRINGS(T4, "T4", "T4");
NVBENCH_DECLARE_TYPE_STRINGS(T5, "T5", "T5");
NVBENCH_DECLARE_TYPE_STRINGS(T6, "T6", "T6");
NVBENCH_DECLARE_TYPE_STRINGS(T7, "T7", "T7");
struct test_size
{
using TL0 = nvbench::type_list<>;
using TL1 = nvbench::type_list<T0>;
using TL2 = nvbench::type_list<T0, T1>;
using TL3 = nvbench::type_list<T0, T1, T2>;
static_assert(nvbench::tl::size<TL0>{} == 0);
static_assert(nvbench::tl::size<TL1>{} == 1);
static_assert(nvbench::tl::size<TL2>{} == 2);
static_assert(nvbench::tl::size<TL3>{} == 3);
};
struct test_get
{
using TL = nvbench::type_list<T0, T1, T2, T3, T4, T5>;