By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,159 Members | 936 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,159 IT Pros & Developers. It's quick & easy.

Template argument deduction

P: n/a
Hi All,

In the book
Working Paper for
Draft Proposed International Standard for Information Systems$)A!*
Programming Language C+ +,
template argument deduction is discussed.

However, the discussion in the above book is too abstract to read.

My question is:
For example, although the definition of bind2nd is

template <class _Operation, class _Tp>
inline binder2nd<_Operation>
bind2nd(const _Operation& __oper, const _Tp& __x)
{
typedef typename _Operation::second_argument_type _Arg2_type;
return binder2nd<_Operation>(__oper, _Arg2_type(__x));
}

we can still call bind2nd without specify _Operation and _Tp
explicitly like.
bind2nd(greater<int>(), 100).
I'm wondering if there any books or webpages which discuss this issue
in great details and provide many examples.

Best wishes,
Peng
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Peng Yu" <pe*******@gmail.com> wrote in message
news:ao********************************@4ax.com...
Hi All,

In the book
Working Paper for
Draft Proposed International Standard for Information Systems$)A!*
Programming Language C+ +,
template argument deduction is discussed.

However, the discussion in the above book is too abstract to read.

My question is:
For example, although the definition of bind2nd is

template <class _Operation, class _Tp>
inline binder2nd<_Operation>
bind2nd(const _Operation& __oper, const _Tp& __x)
{
typedef typename _Operation::second_argument_type _Arg2_type;
return binder2nd<_Operation>(__oper, _Arg2_type(__x));
}

we can still call bind2nd without specify _Operation and _Tp
explicitly like.
bind2nd(greater<int>(), 100).
I'm wondering if there any books or webpages which discuss this issue
in great details and provide many examples.


This concept is known as 'template argument deduction', i.e. in
many cases (but not all), the compiler can deduce the proper types
from the context of the function call (in those cases which it cannot,
it might either choose the wrong instantiation, or issue a diagnostic.
I don't know of any online resources about this, but two books I have
that discuss this imo rather well are:

http://www.josuttis.com/tmplbook/index.html ("Vandevoorde/Jousttis")
http://tinyurl.com/3ot7j ("Austern")

IMO both are good books, but the first goes into greater detail about
the actual mechanics of how C++ templates work. The second is mostly
oriented around practical applications of templates and use of the 'STL'
(the standard library container types).

HTH,
-Mike
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.