Link to home
Start Free TrialLog in
Avatar of Karrtik Iyer
Karrtik IyerFlag for India

asked on

How does boost thread/bind works without variadic templates of c++ 11?

I tried reading some articles over the Internet and also tried to make some sense out of open source code of boost library, however still it is unclear to me how boost thread class (bind) supports and binds variable number of arguments to a function or class even without variadic templates of c++11. Would be grateful if some clearly explains the same since I want to replicate similar feature in a non c++11 environment in my custom library.
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Basically, lots of overloaded template functions. The standard non-variadic implementation supports up to nine arguments.

namespace boost
{
// no arguments

template<class R, class F> unspecified-1 bind(F f);

template<class F> unspecified-1-1 bind(F f);

template<class R> unspecified-2 bind(R (*f) ());

// one argument

template<class R, class F, class A1> unspecified-3 bind(F f, A1 a1);

template<class F, class A1> unspecified-3-1 bind(F f, A1 a1);

template<class R, class B1, class A1> unspecified-4 bind(R (*f) (B1), A1 a1);

template<class R, class T, class A1> unspecified-5 bind(R (T::*f) (), A1 a1);

template<class R, class T, class A1> unspecified-6 bind(R (T::*f) () const, A1 a1);

template<class R, class T, class A1> unspecified-6-1 bind(R T::*f, A1 a1);

// two arguments

template<class R, class F, class A1, class A2> unspecified-7 bind(F f, A1 a1, A2 a2);

template<class F, class A1, class A2> unspecified-7-1 bind(F f, A1 a1, A2 a2);

template<class R, class B1, class B2, class A1, class A2> unspecified-8 bind(R (*f) (B1, B2), A1 a1, A2 a2);

template<class R, class T, class B1, class A1, class A2> unspecified-9 bind(R (T::*f) (B1), A1 a1, A2 a2);

template<class R, class T, class B1, class A1, class A2> unspecified-10 bind(R (T::*f) (B1) const, A1 a1, A2 a2);

// implementation defined number of additional overloads for more arguments
}

namespace
{
 unspecified-placeholder-type-1 _1;

 unspecified-placeholder-type-2 _2;

 unspecified-placeholder-type-3 _3;

// implementation defined number of additional placeholder definitions
}

Open in new window

Avatar of Karrtik Iyer

ASKER

Thanks evilrix. Sorry for going off topic little bit, then how come std::tuple works without C++ 11x, does it also similarly have restrictions of max number of arguments (like 9 in boost bind)?
ASKER CERTIFIED SOLUTION
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks evilrix, I shall read those books that you have suggested, is this the same way even std::tuple available as part of C++ standard library implemented?
In C++11 it uses variadic templates. There was no official std::tuple before this version of the standard.
KarrtikIyer,

If there was something I could have done better to answer your question please let me know as I am always looking to try and improve as an expert. If there was something you still don't understand please ask as I am always happy to provide further clarification. If neither of these are the case I would be very grateful if you would consider reviewing the grading guidelines and augmenting your original grade.

Thank you kindly.
Sorry evilrix, I wasn't aware of the grading policy completely. I shall change the grade, I'm trying to find a way to do it. Thanks for all your help.
Not a problem. It's something  a lot  of people find confusing. It's no biggie, the Moderators can take care of changing the grade for you.

Thsnks for getting back to me and if you do have further questions about this please don't hesitate to ask.