8 template<
typename Type>
11 static constexpr bool value =
false;
14 template<
typename Type_1,
typename Type_2>
17 static constexpr bool value =
true;
20 template<
typename Type>
24 template<
typename Type>
27 static constexpr bool value =
false;
30 template<
typename Type,
typename... Types>
33 static constexpr bool value =
true;
36 template<
typename Type>
40 template<
typename Type>
43 static constexpr bool value =
false;
46 template<
typename... Types>
49 static constexpr bool value =
true;
52 template<
typename Type>
55 template<
typename Type,
typename ReturnType =
void>
58 template<
typename Type,
typename ReturnType =
void>
61 template<
typename Type,
typename ReturnType =
void>
64 template<
size_t StartIndex,
size_t EndIndex>
68 template<
typename VisitorType,
typename VariantType>
72 if constexpr(StartIndex < EndIndex)
74 if(
auto ptr = std::get_if<StartIndex>(&vt))
77 std::get<StartIndex>(visitor.m_visitors)(*ptr);
82 if constexpr (StartIndex + 1 < EndIndex)
85 visit_variant(std::forward<VisitorType>(visitor) , std::forward<VariantType>(vt));
90 template<
typename VisitorType,
typename PairType>
94 if constexpr(StartIndex < EndIndex)
96 auto& [key, vt] = std::forward<PairType>(pair);
98 if(
auto ptr = std::get_if<StartIndex>(&vt))
101 std::get<StartIndex>(visitor.m_visitors)(key, *ptr);
106 if constexpr (StartIndex + 1 < EndIndex)
109 visit_variant(std::forward<VisitorType>(visitor) , std::forward<PairType>(pair));
116 template<
typename VisitorType,
typename VariantType>
117 enable_if_variant_t<VariantType>
118 visit(VisitorType&& visitor, VariantType&& vt)
123 constexpr size_t VariantSize = std::variant_size_v<variant_t>;
126 visit_variant(std::forward<VisitorType>(visitor), std::forward<VariantType>(vt));
130 template<
typename VisitorType,
typename PairType>
131 enable_if_pair_of_variant_t<PairType>
132 visit(VisitorType&& visitor, PairType&& pair)
135 using variant_t =
typename pair_t::second_type;
139 constexpr size_t VariantSize = std::variant_size_v<variant_t>;
142 visit_variant(std::forward<VisitorType>(visitor), std::forward<PairType>(pair));
145 template<
typename... VisitorTypes>
155 template<
typename ContainerType>
158 for(
decltype(
auto) vt:
159 std::forward<ContainerType>(container))
165 template<
typename VariantType>
172 template<
typename PairType>
182 template<
typename... VisitorTypes>
185 template<
typename... VisitorTypes>
189 return { std::forward<VisitorTypes>(visitors)... };
198 using name_t =
const char*;
200 using weight_t = double;
201 using inn_vt_t = std::variant<name_t, age_t>;
203 using variant_t = std::variant<age_t, weight_t, inn_vt_t>;
205 using container_t = std::vector<variant_t>;
209 info.emplace_back( inn_vt_t{
"Thomas Kim"} );
210 info.emplace_back( 30 );
211 info.emplace_back( 60.5 );
212 info.emplace_back( inn_vt_t{
"Sophie Turner"} );
213 info.emplace_back( 20 );
214 info.emplace_back( 56.7 );
245 )(std::forward<
decltype(vt)>(vt));
255 using name_t =
const char*;
257 using weight_t = double;
258 using variant_t = std::variant<name_t, age_t, weight_t>;
260 using container_t = std::set<variant_t>;
264 info.emplace(
"Thomas Kim");
267 info.emplace(
"Sophie Turner");
298 using key_t =
const char*;
299 using name_t =
const char*;
301 using weight_t = double;
302 using variant_t = std::variant<name_t, age_t, weight_t>;
304 using container_t = std::map<key_t, variant_t>;
308 info[
"Programmer"] =
"Thomas Kim";
310 info[
"Weight"] = 60.5;
311 info[
"Actress"] =
"Sophie Turner";
312 info[
"Her age"] = 20;
313 info[
"Her weight"] = 56.7;
void test_visit_simplified_map()
void test_visit_simplified()
void test_visit_simplified_set()
Type to string name conversions are defined.
std::enable_if_t< is_variant_type_v< Type >, ReturnType > enable_if_variant_t
std::enable_if_t< is_pair_type_v< Type >, ReturnType > enable_if_pair_t
constexpr bool is_variant_type_v
enable_if_variant_t< VariantType > visit(VisitorType &&visitor, VariantType &&vt)
overloaded(VisitorTypes...) -> overloaded< VisitorTypes... >
overloaded< remove_cv_ref_t< VisitorTypes >... > make_overloads(VisitorTypes &&... visitors)
constexpr bool is_pair_of_variant_type_v
std::enable_if_t< is_pair_of_variant_type_v< Type >, ReturnType > enable_if_pair_of_variant_t
constexpr bool is_pair_type_v
std::enable_if_t< is_pair_of_variant_v< remove_cv_ref_t< PairType > > > visit_variant(VisitorType &&visit, PairType &&vpr)
std::remove_cv_t< std::remove_reference_t< Type > > remove_cv_ref_t
Remove const volatile reference from Type.
static enable_if_pair_of_variant_t< PairType > visit_variant(VisitorType &&visitor, PairType &&pair)
static enable_if_variant_t< VariantType > visit_variant(VisitorType &&visitor, VariantType &&vt)
static constexpr bool value
static constexpr bool value
static constexpr bool value
void for_each(ContainerType &&container)
std::tuple< VisitorTypes... > vistors_t
enable_if_variant_t< VariantType > operator()(VariantType &&vt) const
enable_if_pair_of_variant_t< PairType > operator()(PairType &&vt)
overloaded(VisitorTypes... visitors)
Stream output operators << are implemented.