[type_traits] type_traits for types with operator().
Hello. Recently I looked for type_traits for callable classes. It so strange, I didn't find such traits. Most likely, I just missed them or something like them. I actually don't know is there a real need for them. Anyway I tried to write such traits at least for practice and metaprogramming training. I tested them with gcc, clang and msvc2010. I would appreciate if you looked at the code. Here is the linkhttps://github.com/AntonBikineev/is_functional/ to my github repository. It's cool that they can see hidden generated operator() of lambdas closure type. Best regards, Anton.
Recently I looked for type_traits for callable classes. It so strange, I didn't find such traits. Most likely, I just missed them or something like them.
I actually don't know is there a real need for them. Anyway I tried to write such traits at least for practice and metaprogramming training. I tested them with gcc, clang and msvc2010. I would appreciate if you looked at the code. Here is the linkhttps://github.com/AntonBikineev/is_functional/ to my github repository.
It's cool that they can see hidden generated operator() of lambdas closure type.
My apologies for not replying before Anton.
This looks cool. However what does it detect? Any operator() or nullary
operator()?
A better C++11 style interface *if* it can be implemented would be something
like:
template
On 29/01/2014 02:28 p.m., John Maddock wrote:
Recently I looked for type_traits for callable classes. It so strange, I didn't find such traits. Most likely, I just missed them or something like them.
I actually don't know is there a real need for them. Anyway I tried to write such traits at least for practice and metaprogramming training. I tested them with gcc, clang and msvc2010. I would appreciate if you looked at the code. Here is the linkhttps://github.com/AntonBikineev/is_functional/ to my github repository.
It's cool that they can see hidden generated operator() of lambdas closure type.
My apologies for not replying before Anton.
This looks cool. However what does it detect? Any operator() or nullary operator()?
AFAIK it detects only the basic case of a single non-templated `operator()` with any number of arguments.
A better C++11 style interface *if* it can be implemented would be something like:
template
struct is_callable; Which inherits from true_type only if F is callable with arguments Args...
The tricky part is creating a decent interface that can deal with both lvalue and rvalue refs as arguments correctly.
Actually I was sure there was something similar in the C++11 std, but I couldn't find anything.
Not in C++11, but C++14 std::result_of
On 29 January 2014 17:28, John Maddock wrote:
A better C++11 style interface *if* it can be implemented would be something like:
template
struct is_callable; Which inherits from true_type only if F is callable with arguments Args...
The tricky part is creating a decent interface that can deal with both lvalue and rvalue refs as arguments correctly.
Actually I was sure there was something similar in the C++11 std, but I couldn't find anything.
It doesn't exist, but all std::lib implementations need something like
it, so it would be a good candidate for standardisation.
The traits in http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3866.html
provide even more functionality. is_callable
On 01/29/2014 12:28 PM, John Maddock wrote:
Recently I looked for type_traits for callable classes. It so strange, I didn't find such traits. Most likely, I just missed them or something like them.
I actually don't know is there a real need for them. Anyway I tried to write such traits at least for practice and metaprogramming training. I tested them with gcc, clang and msvc2010. I would appreciate if you looked at the code. Here is the linkhttps://github.com/AntonBikineev/is_functional/ to my github repository.
It's cool that they can see hidden generated operator() of lambdas closure type.
My apologies for not replying before Anton.
This looks cool. However what does it detect? Any operator() or nullary operator()?
A better C++11 style interface *if* it can be implemented would be something like:
template
struct is_callable; Which inherits from true_type only if F is callable with arguments Args...
There has been some discussion on implementing this sort of interface on this mailing list, some in the last few weeks and some closer to a year ago, IIRC. I believe there is at least one implementation out there that provides a has_call trait. As you pointed out, though, there are a lot of cases to handle, and I'm not sure that it covers all of the bases. Jason
This looks cool. However what does it detect? Any operator() or nullary operator()?
It detects any operator(), because expression &detail::is_functional_composed<T>::operator() is ambiguos when detail::is_functional_composed<T> has two or more operator(). But is_callable looks really better. Sorry for suggestion. Best regards, Anton.
participants (5)
-
Agustín K-ballo Bergé
-
Anton Bikineev
-
Jason Roehm
-
John Maddock
-
Jonathan Wakely