|
Boost : |
Subject: Re: [boost] [type_traits] type_traits for types with operator().
From: Agustín K-ballo Bergé (kaballo86_at_[hidden])
Date: 2014-01-29 12:37:45
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
>> link<https://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 <class F, class Args...>
> 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<F(Args...)> is SFINAE friendly,
so it's only a matter of detecting a nested typedef `type`.
I have done some research on the subject, leading to this article:
http://talesofcpp.fusionfenix.com/post-11/true-story-call-me-maybe
and this implementation:
https://github.com/STEllAR-GROUP/hpx/blob/master/hpx/traits/is_callable.hpp
Regards,
-- Agustín K-ballo Bergé.- http://talesofcpp.fusionfenix.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk