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.
LVL 15
Karrtik IyerSoftware ArchitectAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

evilrixSenior Software Engineer (Avast)Commented:
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

 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

Karrtik IyerSoftware ArchitectAuthor Commented:
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)?
evilrixSenior Software Engineer (Avast)Commented:
Boost tuple basically uses nested template pairs. So tuble<A, B, C> is actually represented something like tuple<A, tuple<B, tuple<C, TermType>>>, where TermType is a sentinel type that ends the recursion.

Notice how boost uses macros to access them? This is to hide the nasty syntax.

I recommend getting hold of the book C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond, as it explains all these techniques, most of which are borrowed from the Boost MPL (Meta Programming Language).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

Karrtik IyerSoftware ArchitectAuthor Commented:
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?
evilrixSenior Software Engineer (Avast)Commented:
In C++11 it uses variadic templates. There was no official std::tuple before this version of the standard.
evilrixSenior Software Engineer (Avast)Commented:

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.
Karrtik IyerSoftware ArchitectAuthor Commented:
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.
evilrixSenior Software Engineer (Avast)Commented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.