问题 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,
问题 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,
问题 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