Re: boost::tuple<...involving template arguments...>
On Feb 12, 10:20 pm, er <erwann.rog...@gmail.com> wrote:
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.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34