10 using name_t =
const char*;
12 using weight_t = double;
14 using price_t = float;
15 using title_t =
const char*;
17 using author_t =
const char*;
19 using snack_t = std::tuple<name_t, weight_t>;
20 using book_t = std::tuple<title_t, price_t, author_t>;
21 using device_t = std::tuple<name_t, price_t, weight_t>;
25 using bag_t = std::vector<item_t>;
29 bag.emplace_back( snack_t{
"Honey choco", 300.0 });
31 bag.emplace_back( book_t{
"Good Programmer", 30.0f,
"Thomas Kim" });
33 bag.emplace_back( device_t{
"Good Programmer", 1000.0f, 1.6 });
45 using name_t =
const char*;
47 using weight_t = double;
49 using price_t = float;
50 using title_t =
const char*;
51 using author_t =
const char*;
53 using snack_t = std::tuple<name_t, weight_t>;
54 using snacks_t = std::vector<snack_t>;
56 using book_t = std::tuple<title_t, price_t, author_t>;
57 using books_t = std::vector<book_t>;
59 using device_t = std::tuple<name_t, price_t, weight_t>;
60 using devices_t = std::vector<device_t>;
67 mine = snack_t{
"Yummy Choco", 300.0 };
71 mine = snacks_t{ snack_t{
" Yummy Choco", 300}, snack_t{
"Sweet Potato", 200} };
75 mine = books_t{ book_t{
"Good Book", 20.0f,
"Thomas Kim"},
76 book_t{
"Poor Book", 20.0f,
"Thomas Kim"}, book_t{
"Excellent Book", 20.0f,
"Thomas Kim"} };
85 using cate_t =
const char*;
86 using name_t =
const char*;
88 using weight_t = double;
90 using price_t = float;
91 using title_t =
const char*;
92 using author_t =
const char*;
94 using book_t = std::tuple<cate_t, title_t, weight_t>;
95 using device_t = std::tuple<cate_t, name_t, price_t>;
98 using person_t = std::tuple<cate_t, thing_t>;
100 person_t tom{
"person", book_t{
"book",
"Good Man", 300 } };
104 tom = person_t{
"person", device_t{
"device",
"MyPowerLaptop", 1000} };
108 auto& [cate, thing] = tom;
112 thing.if_current_type<book_t>([](
auto&& book)
114 stream <<
"I love this book [" << book <<
"]" <<
endl;
117 thing.if_current_type<device_t>([](
auto&& device)
119 stream <<
"I love this device [" << device <<
"]" <<
endl;
125 using name_t =
const char*;
127 using weight_t = double;
129 enum {idx_name, idx_age, idx_weight};
133 using tuple_t = std::tuple<name_t, any_t>;
135 using container_t = std::vector<tuple_t>;
139 things.emplace_back(
"name",
"Thomas Kim");
140 things.emplace_back(
"age", 30);
141 things.emplace_back(
"weight", 60.0);
145 auto handle_name = [](
auto&& value)
147 stream <<
"\""<< value <<
"\" is my friend!" <<
endl;
150 auto handle_age = [](
auto&& value)
152 stream <<
"He is "<< value <<
" old." <<
endl;
155 auto handle_weight = [](
auto&& value)
157 stream <<
"He weighs "<< value <<
" kilogram." <<
endl;
160 for(
auto&& thing: things)
162 auto[cate, item] = thing;
164 types::handle_any(item, handle_name, handle_age, handle_weight);
169 for(
auto&& thing: things)
171 auto[cate, item] = thing;
173 item.if_current_type<name_t>(handle_name);
179 for(
auto&& thing: things)
181 auto[cate, item] = thing;
183 types::if_current_index<idx_name>(item, handle_name);
void _2_test_print_elements()
void _1_test_type_functions()
void _4_test_any_as_container_elements()
void _3_test_any_as_tuple_elements()
Type to string name conversions are defined.
Stream output operators << are implemented.