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

Discussion in 'C++' started by er, Feb 12, 2008.

  1. er

    er Guest

    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.
     
    er, Feb 12, 2008
    #1
    1. Advertising

  2. 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
     
    Victor Bazarov, Feb 12, 2008
    #2
    1. Advertising

  3. er

    er Guest

    On Feb 12, 4:34 pm, "Victor Bazarov" <> 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?
     
    er, Feb 12, 2008
    #3
  4. er wrote:
    > On Feb 12, 4:34 pm, "Victor Bazarov" <> 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
     
    Victor Bazarov, Feb 12, 2008
    #4
  5. er

    Pete Becker Guest

    On 2008-02-12 16:20:34 -0500, er <> 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)
     
    Pete Becker, Feb 12, 2008
    #5
  6. er

    James Kanze Guest

    On Feb 12, 10:20 pm, 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.


    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:
    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
     
    James Kanze, Feb 13, 2008
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michal Mikolajczyk
    Replies:
    1
    Views:
    839
    Larry Bates
    Apr 20, 2004
  2. Jeff Epler
    Replies:
    0
    Views:
    1,046
    Jeff Epler
    Apr 20, 2004
  3. Bill Scherer
    Replies:
    0
    Views:
    638
    Bill Scherer
    Apr 20, 2004
  4. Gregor Horvath

    Why tuple with one item is no tuple

    Gregor Horvath, Mar 15, 2005, in forum: Python
    Replies:
    37
    Views:
    868
    Antoon Pardon
    Mar 30, 2005
  5. Stuart
    Replies:
    6
    Views:
    239
    Seungbeom Kim
    Mar 11, 2013
Loading...

Share This Page