template-meta-programming

Concise bidirectional static 1:1 mapping of values and types

不羁岁月 提交于 2020-07-17 11:18:13
问题 I'm going to start with how I imagine using the code I'd like to create. It doesn't have to be exactly like this but it's a good example of what I mean by "concise" in the title. In my case it's mapping of a type to a related enumeration value. struct bar : foo<bar, foo_type::bar> { /* ... */ }; // \_/ \___________/ // ^ Type ^ Value What this should ideally do is an automatic registration of a bidirectional mapping between the first template parameter of foo , a type, and second, a value,

Concise bidirectional static 1:1 mapping of values and types

╄→尐↘猪︶ㄣ 提交于 2020-07-17 11:16:41
问题 I'm going to start with how I imagine using the code I'd like to create. It doesn't have to be exactly like this but it's a good example of what I mean by "concise" in the title. In my case it's mapping of a type to a related enumeration value. struct bar : foo<bar, foo_type::bar> { /* ... */ }; // \_/ \___________/ // ^ Type ^ Value What this should ideally do is an automatic registration of a bidirectional mapping between the first template parameter of foo , a type, and second, a value,

Check if a class has a possibly-overloaded function call operator

。_饼干妹妹 提交于 2020-06-27 04:11:14
问题 I am wondering whether it would be possible to implement a trait in C++20 to check if a type T is such that it has a possibly overloaded/possibly templated function call operator: operator() . // Declaration template <class T> struct has_function_call_operator; // Definition ??? // Variable template template <class T> inline constexpr bool has_function_call_operator_v = has_function_call_operator<T>::value; so that a code such as the following would lead to the correct result: #include