Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > boost::tuple<...involving template arguments...>

Reply
Thread Tools

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

 
 
er
Guest
Posts: n/a
 
      02-12-2008
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.
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      02-12-2008
er 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.


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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
 
er
Guest
Posts: n/a
 
      02-12-2008
On Feb 12, 4:34 pm, "Victor Bazarov" <(E-Mail Removed)> wrote:
> er 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.

>
> 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
> --
> Please remove capital 'A's when replying by e-mail
> I do not respond to top-posted replies, please don't ask


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?

 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      02-12-2008
er wrote:
> On Feb 12, 4:34 pm, "Victor Bazarov" <(E-Mail Removed)> wrote:
>> er 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.

>>
>> 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
>> --
>> Please remove capital 'A's when replying by e-mail
>> I do not respond to top-posted replies, please don't ask

>
> 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?


I guess you need to know that there exists this:
http://www.boost.org/more/mailing_lists.htm#users
....and other stuff on their web site. Use it.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
Pete Becker
Guest
Posts: n/a
 
      02-12-2008
On 2008-02-12 16:20:34 -0500, er <(E-Mail Removed)> said:

> 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>();

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      02-13-2008
On Feb 12, 10:20 pm, er <(E-Mail Removed)> 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:(E-Mail Removed)
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
r H2 deduce deduce template argument of a template class inheritingfrom a non template base? nguillot C++ 5 03-08-2009 05:56 PM
How to use the template member function of a template in the memberfunction of another template class? Peng Yu C++ 3 10-26-2008 03:51 PM
template template arguments: expected a class template, got `Component<T1, T2, T3> gary.bernstein@gmail.com C++ 1 06-08-2007 07:10 AM
Re: A Newbie Question about template template template tom_usenet C++ 0 07-24-2003 12:06 PM
Re: A Newbie Question about template template template Chris Theis C++ 2 07-24-2003 09:42 AM



Advertisments