boost::tuple<...involving template arguments...>

E

er

Hi,

I have the following:

template<typename T>
class A: public std::unary_function<const boost::tuple<double,const
T&>&, void>{
public:
typedef typename std::unary_function<const boost::tuple<double,const
T&>&, void> parent_type;
typedef typename parent_type::argument_type argument_type;
void operator()(argument_type t)const{
t.get<0>(); //error: expected primary-expression before ')' token
t.get<1>(); //error: expected primary-expression before ')' token
};
};

Similar code without the template (i.e. fix say T = double) works
fine.

Anybody, pls help. Thanks.
 
V

Victor Bazarov

er said:
I have the following:

template<typename T>
class A: public std::unary_function<const boost::tuple<double,const
T&>&, void>{
public:
typedef typename std::unary_function<const boost::tuple<double,const
T&>&, void> parent_type;
typedef typename parent_type::argument_type argument_type;
void operator()(argument_type t)const{
t.get<0>(); //error: expected primary-expression before ')' token
t.get<1>(); //error: expected primary-expression before ')' token
};
};

Similar code without the template (i.e. fix say T = double) works
fine.

Have you tried a different compiler? Have you tried asking in
a Boost discussion forum?

As I can see, the new standard template 'tuple' has 'get' members
that happen to have one argument. Your code calls 'get' without
any arguments. Perhaps you should RTFM...

V
 
E

er

Have you tried a different compiler? Have you tried asking in
a Boost discussion forum?

As I can see, the new standard template 'tuple' has 'get' members
that happen to have one argument. Your code calls 'get' without
any arguments. Perhaps you should RTFM...

V

Thanks. I'm only aware of t.get<N>() or get<N>(t) and both give an
error... is there something that i don't know then?
 
P

Pete Becker

void operator()(argument_type t)const{
t.get<0>(); //error: expected primary-expression before ')' token
t.get<1>(); //error: expected primary-expression before ')' token

I don't know about Boost, but with TR1 and C++0x, get is a non-member,
so the code should be

get<0>(t)
get<1>(t)

If get is a member template, then you probably have to say so:

t.template get<0>();
t.template get<1>();
 
J

James Kanze

I have the following:
template<typename T>
class A: public std::unary_function<const boost::tuple<double,const
T&>&, void>{
public:
typedef typename std::unary_function<const boost::tuple<double,const
T&>&, void> parent_type;
typedef typename parent_type::argument_type argument_type;
void operator()(argument_type t)const{
t.get<0>(); //error: expected primary-expression before ')' token
t.get<1>(); //error: expected primary-expression before ')' token
};
};
Similar code without the template (i.e. fix say T = double) works
fine.

t.get is a dependent expression, which means that the compiler
doesn't know that get is a template when it first parses the
expression. It thus interprets the < as a less than operator,
rather than opening a template argument lest, and the > as the
greater than operator. And of course, there's no way a greater
than operator can ever be followed by an empty set of
parentheses, so the compiler complains. Since the compiler
can't know that get will be a template, you have to tell it:

t. template get<0>() ;

And of course, if the code isn't a template, there's no
dependent name, the compiler knows what get is, and can parse
the thing correctly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top