0

I was browsing through Nano-signal-slot source code and hoping it could help me implement signals and slots functionality into my application using C++11 and I came across a portion of code that I haven't seen before.

Portion of code:

/* ... */

template <typename Re_t> class function;
template <typename Re_t, typename... Args>
class function<Re_t(Args...)>
{
    void *m_this_ptr;
    Re_t(*m_stub_ptr)(void*, Args...);

/* ... */

More specifically:

class function<Re_t(Args...)>

What does do after the class name?

6
  • It's a variadic template, note the ... operator (multiple template arguments)
    – Joseph
    Commented Mar 3, 2014 at 22:37
  • 1
    It allows you to specify the argument types of the function type (I'm presuming you're referring to the (Args...) portion). BTW, off-topic, why don't you have a look at Qt, it has a straightforward and extensive (and thread-safe) signal/slot mechanism built in.
    – Jason C
    Commented Mar 3, 2014 at 22:38
  • Is it right to call it a variadic template? I'd say it's a variadic template specialisation of a non-variadic template.
    – user743382
    Commented Mar 3, 2014 at 22:39
  • 3
    This code contains a forward-declaration of a class template: template <typename Re_t> class function; and a subsequent partial specialization of said class template: template <typename Re_t, typename... Args> class function<Re_t(Args...)> { /*...*/ }; (Use these terms to find more information.)
    – dyp
    Commented Mar 3, 2014 at 22:39
  • 1
    possible duplicate of Function signature-like expressions as C++ template arguments
    – Jason C
    Commented Mar 3, 2014 at 22:46

1 Answer 1

8

class function<Re_t(Args...)> defines a partial specialization of the templated class function<T>. Basically this allows you to write a specialization in the form of a functor, such as:

function<int(double,unsigned)> foo = ...

Note that you can have a variable number of arguments due to the use of Args....

1
  • Thank you :) I wasn't sure what <Re_t(Args...)> does after the class name.
    – SLC
    Commented Mar 3, 2014 at 22:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.