Gyselalib++
 
Loading...
Searching...
No Matches
test_utils.hpp
1#pragma once
2
3#include <tuple>
4#include <type_traits>
5#include <utility>
6
7#include <gtest/gtest.h>
8
13template <class S>
15{
16 using type = S;
17};
18
19template <class T, T... Ints>
20struct to_tuple<std::integer_sequence<T, Ints...>>
21{
22 using type = std::tuple<std::integral_constant<T, Ints>...>;
23};
24
25template <class T, class U>
26struct to_tuple<std::pair<T, U>>
27{
28 using type = std::tuple<T, U>;
29};
30
31template <class S>
32using to_tuple_t = typename to_tuple<S>::type;
33
34template <class TupleOfTuples, class Tuple>
36
37template <class... Tuples, class Tuple>
38struct for_each_tuple_cat<std::tuple<Tuples...>, Tuple>
39{
40 using type = std::tuple<
41 decltype(std::tuple_cat(std::declval<Tuples>(), std::declval<Tuple>()))...>;
42};
43
45template <class TupleOfTuples, class Tuple>
46using for_each_tuple_cat_t = typename for_each_tuple_cat<TupleOfTuples, Tuple>::type;
47
48static_assert(std::is_same_v<
49 for_each_tuple_cat_t<
50 std::tuple<std::tuple<double, double>, std::tuple<int, double>>,
51 std::tuple<int>>,
52 std::tuple<std::tuple<double, double, int>, std::tuple<int, double, int>>>);
53
54static_assert(std::is_same_v<
55 for_each_tuple_cat_t<std::tuple<std::tuple<double, double>>, std::tuple<int>>,
56 std::tuple<std::tuple<double, double, int>>>);
57
58template <class InTupleOfTuples, class OutTupleOfTuples>
60
61template <class... HeadArgs, class... TailTuples, class OutTupleOfTuples>
62struct cartesian_product_impl<std::tuple<std::tuple<HeadArgs...>, TailTuples...>, OutTupleOfTuples>
64 std::tuple<TailTuples...>,
65 decltype(std::tuple_cat(
66 std::declval<
67 for_each_tuple_cat_t<OutTupleOfTuples, std::tuple<HeadArgs>>>()...))>
68{
69};
70
71template <class OutTupleOfTuples>
72struct cartesian_product_impl<std::tuple<>, OutTupleOfTuples>
73{
74 using type = OutTupleOfTuples;
75};
76
79template <class... InTuplesLike>
80using cartesian_product_t = typename cartesian_product_impl<
81 std::tuple<to_tuple_t<InTuplesLike>...>,
82 std::tuple<std::tuple<>>>::type;
83
84static_assert(std::is_same_v<
85 cartesian_product_t<std::tuple<int, float>, std::tuple<double>>,
86 std::tuple<std::tuple<int, double>, std::tuple<float, double>>>);
87
89template <class T>
91{
92 using type = T;
93};
94
95template <class... Args>
96struct tuple_to_types<std::tuple<Args...>>
97{
98 using type = testing::Types<Args...>;
99};
100
101template <class T>
102using tuple_to_types_t = typename tuple_to_types<T>::type;
A class which describes the real space in the temporal direction.
Definition geometry.hpp:44
Definition test_utils.hpp:59
Definition test_utils.hpp:35
Transform a sequence S to a tuple:
Definition test_utils.hpp:15
Transform a std::tuple<Args...> to a testing::Types<Args...>, identity otherwise.
Definition test_utils.hpp:91