Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Something I had worked on that does what you want I think -- it is however limited to functors that define at most one function call operator (lambdas fit this restriction). It also works on MSVC 2012 CTP.</p> <pre><code>namespace detail { //////////////////////////////////////////////////////////////////////////// //! Select between function pointer types //////////////////////////////////////////////////////////////////////////// template &lt;typename T&gt; struct callable_helper_ptr; //! non-member functions template &lt;typename R, typename... Args&gt; struct callable_helper_ptr&lt;R (*)(Args...)&gt; { typedef void object_t; typedef R result_t; typedef std::tuple&lt;Args...&gt; args_t; }; //! member functions template &lt;typename R, typename O, typename... Args&gt; struct callable_helper_ptr&lt;R (O::*)(Args...)&gt; { typedef O object_t; typedef R result_t; typedef std::tuple&lt;Args...&gt; args_t; }; //! const member functions template &lt;typename R, typename O, typename... Args&gt; struct callable_helper_ptr&lt;R (O::*)(Args...) const&gt; { typedef O object_t; typedef R result_t; typedef std::tuple&lt;Args...&gt; args_t; }; //////////////////////////////////////////////////////////////////////////// //! Select between function pointers and functors //////////////////////////////////////////////////////////////////////////// template &lt;typename T, typename is_ptr = typename std::is_pointer&lt;T&gt;::type&gt; struct callable_helper; //! specialization for functors (and lambdas) template &lt;typename T&gt; struct callable_helper&lt;T, std::false_type&gt; { typedef callable_helper_ptr&lt;decltype(&amp;T::operator())&gt; type; }; //! specialization for function pointers template &lt;typename T&gt; struct callable_helper&lt;T, std::true_type&gt; { typedef callable_helper_ptr&lt;T&gt; type; }; } //namespace detail //////////////////////////////////////////////////////////////////////////////// //! defines the various details of a callable object T //////////////////////////////////////////////////////////////////////////////// template &lt;typename T&gt; struct callable_traits { typedef typename detail::callable_helper&lt;T&gt;::type::object_t object_t; typedef typename detail::callable_helper&lt;T&gt;::type::result_t result_t; typedef typename detail::callable_helper&lt;T&gt;::type::args_t args_t; template &lt;unsigned N&gt; struct arg : public std::tuple_element&lt;N, args_t&gt; {}; }; </code></pre> <p>And my write up on the process behind writing if anyone is interested: <a href="http://bkentel.wordpress.com/2012/12/12/defining-a-traits-type-for-callable-objects/" rel="nofollow">http://bkentel.wordpress.com/2012/12/12/defining-a-traits-type-for-callable-objects/</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload