473,386 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Template argument deduction

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
1 1695
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Suzanne Vogel | last post by:
Is it possible to store a pointer to a template function? eg, template<class T> fooFunc() {...} fptr = fooFunc; // <-- I couldn't find any info here, not even in the forums:...
4
by: Dave | last post by:
Hello all, Consider this template: template <typename T> void foo(T bar) {...} Here are three ways to instantiate this: 1.
2
by: marco | last post by:
the problem: I use a typedef inside a class template, than I use this type (dim_v<N1>::Type) to define the argument of a template function f but when I call this function from main, the compiler...
3
by: BigMan | last post by:
Here is a piece of code: #include <memory> using namespace std; template< typename SomeType > void f(auto_ptr_ref< SomeType >) { }
14
by: Bart Samwel | last post by:
Hi everybody, I would really like some help explaining this apparent discrepancy, because I really don't get it. Here is the snippet: void foo(int&); void foo(int const&); ...
4
by: George | last post by:
Dear All, I'm compiling the code below with IBM's xlC 6.0 and get the message, "rmspace.cpp", line 34.48: 1540-0298 (S) Template argument deduction cannot be performed using the function...
5
by: ma740988 | last post by:
// trial.h #ifndef TRIAL_H #define TRIAL_H # include <vector> # include <complex> # include <iostream> template <typename scalar>
7
by: gretean | last post by:
I have a problem that's driving me crazy involving Microsoft's ability to deduce template parameters. I am using Visual Studio .NET (aka VC7?), and it gives an error compiling the following code....
3
by: Fei Liu | last post by:
Hello, We all know that a template function can automatically deduce its parameter type and instantiate, e.g. template <tpyename T> void func(T a); func(0.f); This will cause func<floatto...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.