C++ Library Extensions 2022.12.09
To help learn modern C++ programming
001-type_to_string.cpp
Go to the documentation of this file.
1
13#include <iostream>
14#include <tpf_types.hpp>
15
16// Examples for type::type_to_string(), Tpf_GetTypeName(),
17// Tpf_GetTypeCategory(), Tpf_GetValueCategory()
19{
20 // namespace alias for tpf::types
21 namespace types = tpf::types;
22
23 // an instance of type int
24 int n;
25
26 // when a type type_arg is passed as argument
27 // to Tpf_GetTypeName(type_arg), it returns
28 // string name of the type_arg
29 std::cout << "Type type name of type int : "
30 << Tpf_GetTypeName(int) << std::endl;
31
32 // type category of an object n of type int
33 using type_category_of_n_t = decltype(n);
34
35 // value category of an object n of type int
36 using value_category_of_n_t = decltype((n));
37
38 // when a type type_arg is passed as a template parameter
39 // types::type_to_string<type_arg>() returns
40 // string name of the type_arg
41 std::cout << "Type category of n: "
42 << types::type_to_string<type_category_of_n_t>() << std::endl;
43
44 // when a type type_arg is passed as a template parameter
45 // types::type_to_string<type_arg>() returns
46 // string name of the type_arg
47 std::cout << "Value category of n: "
48 << types::type_to_string<value_category_of_n_t>() << std::endl;
49
50 // when a type type_arg is passed as a template parameter
51 // types::type_to_string<type_arg>() returns
52 // string name of the type_arg
53 std::cout << "Type category of n: "
55
56 // when a type type_arg is passed as a template parameter
57 // types::type_to_string<type_arg>() returns
58 // string name of the type_arg
59 std::cout << "Value category of n: "
61
62 // when a type type_arg is passed as a template parameter
63 // types::type_to_string<type_arg>() returns
64 // string name of the type_arg
65 std::cout << "Type category of n: "
66 << Tpf_GetTypeName(decltype(n)) << std::endl;
67
68 // when a type type_arg is passed as a template parameter
69 // types::type_to_string<type_arg>() returns
70 // string name of the type_arg
71 std::cout << "Value category of n: "
72 << Tpf_GetTypeName(decltype((n))) << std::endl;
73}
74
75int main()
76{
78}
void example_type_to_string()
int main()
auto & cout
auto & endl
Type to string name conversions are defined.
Definition: 31-visit.cpp:7
Type functions are implemented.
#define Tpf_GetValueCategory(instance_arg)
A macro that returns instance_arg's value category string name.
Definition: tpf_types.hpp:1434
#define Tpf_GetTypeName(type_arg)
A macro that returns type_arg's string name.
Definition: tpf_types.hpp:1422
#define Tpf_GetTypeCategory(instance_arg)
A macro that returns instance_arg's type category string name.
Definition: tpf_types.hpp:1428