18 template<
typename Type>
21 template<
typename Type>
24 static constexpr bool value =
false;
27 template<
typename... Types>
30 static constexpr bool value =
true;
33 template<
typename Type>
36 template<
typename Type>
39 static constexpr bool value =
false;
42 template<
typename... Types>
45 static constexpr bool value =
true;
48 template<
typename Type>
51 template<
typename... Types>
52 void print_tuple(std::ostream& os,
const std::tuple<Types...>& tpl);
54 template<
typename Type,
typename... Types>
55 void print_variant(std::ostream& os,
const std::variant<Type, Types...>& vrt);
57 template<
size_t StartIndex,
size_t EndIndex>
60 template<
typename TupleType>
61 static void print_tuple(std::ostream& os,
const TupleType& tpl)
63 if constexpr( StartIndex != EndIndex )
65 auto& e = std::get<StartIndex>(tpl);
69 using ele_t =
decltype(e);
71 if constexpr(is_tuple_v<ele_t>)
75 else if constexpr(is_variant_v<ele_t>)
85 if constexpr(StartIndex + 1 < EndIndex)
93 template<
typename VariantType>
96 if constexpr(StartIndex != EndIndex)
98 if(
auto ptr = std::get_if<StartIndex>(&vrt))
101 using ele_t =
decltype(*ptr);
103 if constexpr(is_variant_v<ele_t>)
107 else if constexpr(is_tuple_v<ele_t>)
120 if constexpr(StartIndex + 1 < EndIndex )
128 template<
typename... Types>
129 void print_tuple(std::ostream& os,
const std::tuple<Types...>& tpl)
131 if constexpr(
sizeof...(Types) == 0)
144 template<
typename Type,
typename... Types>
145 void print_variant(std::ostream& os,
const std::variant<Type, Types...>& vrt)
149 if(vrt.index() != std::variant_npos)
153 template<
typename... Types>
154 std::ostream&
operator<<(std::ostream& os,
const std::tuple<Types...>& tpl)
160 template<
typename Type,
typename... Types>
161 std::ostream&
operator<<(std::ostream& os,
const std::variant<Type, Types...>& vrt)
172 using name_t = std::string;
174 using weight_t = double;
176 using tuple_t = std::tuple<name_t, age_t, weight_t>;
177 using variant_t = std::variant<name_t, age_t, weight_t>;
179 tuple_t t{
"Sophie Turner", 20, 56.5};
181 variant_t v {
"Thomas Kim"};
193 using name_t = std::string;
195 using weight_t = double;
197 using tpl_t = std::tuple<name_t, age_t, weight_t>;
198 using vrt_t = std::variant<name_t, age_t, weight_t>;
202 using tuple_t = std::tuple<name_t, tpl_t, vrt_t>;
206 using variant_t = std::variant<name_t, tpl_t, vrt_t>;
208 tuple_t t {
"Advanced Tuple", tpl_t{
"Sophie Turner", 20, 56.7}, vrt_t{
"Steven Lee"} };
210 variant_t v { tpl_t{
"Advanced Variant", 1, 22.0 / 7.0} };
void test_advanced_tuple_variant()
void test_simple_tuple_variant()
constexpr bool is_tuple_v
constexpr bool is_variant_v
std::remove_cv_t< std::remove_reference_t< Type > > remove_cv_ref_t
void print_tuple(std::ostream &os, const std::tuple< Types... > &tpl)
std::ostream & operator<<(std::ostream &os, const std::tuple< Types... > &tpl)
void print_variant(std::ostream &os, const std::variant< Type, Types... > &vrt)
static constexpr bool value
static constexpr bool value
static void print_variant(std::ostream &os, const VariantType &vrt)
static void print_tuple(std::ostream &os, const TupleType &tpl)