template template parameters with a default - build error that oncedid not occur (new gcc?)

Discussion in 'C++' started by er, Aug 24, 2008.

  1. er

    er Guest

    Hi all,

    I have some build errors related to template templates that once
    compiled fine, but not anymore. i'm guessing this might be due to an
    upgrade in gcc (i upgraded from ubuntu 7.10 to 8.04).

    suppose i have a template class like this:

    template<typename ValueType,template<typename> class F>
    struct A{
    typedef F<ValueType> f_type;
    };

    and in a source file I have:

    typedef A<ValueType,std::vector> a_type;

    This used to work fine, not anymore:

    expected a template of type ‘template<class> class F’, got
    ‘template<class _Tp, class _Alloc> class std::vector’

    I understand this error message, it's just that _Alloc usually has a
    default, which previously allowed the definition of A as above, not
    anymore! I have to refactor my code, any suggestion?

    Thanks!
     
    er, Aug 24, 2008
    #1
    1. Advertising

  2. er

    er Guest

    Re: template template parameters with a default - build error thatonce did not occur (new gcc?)

    On Aug 24, 4:41 pm, er <> wrote:
    > Hi all,
    >
    > I have some build errors related to template templates that once
    > compiled fine, but not anymore. i'm guessing this might be due to an
    > upgrade in gcc (i upgraded from ubuntu 7.10 to 8.04).
    >
    > suppose i have a template class like this:
    >
    > template<typename ValueType,template<typename> class F>
    > struct A{
    >   typedef F<ValueType> f_type;
    >
    > };
    >
    > and in a source file I have:
    >
    > typedef A<ValueType,std::vector> a_type;
    >
    > This used to work fine, not anymore:
    >
    > expected a template of type ‘template<class> class F’, got
    > ‘template<class _Tp, class _Alloc> class std::vector’
    >
    > I  understand this error message, it's just that _Alloc usually has a
    > default, which previously allowed the definition of A as above, not
    > anymore! I have to refactor my code, any suggestion?
    >
    > Thanks!


    ps: i believe I'm using gcc 4.2.3
     
    er, Aug 24, 2008
    #2
    1. Advertising

  3. er

    Ian Collins Guest

    Re: template template parameters with a default - build error thatonce did not occur (new gcc?)

    er wrote:
    > Hi all,
    >
    > I have some build errors related to template templates that once
    > compiled fine, but not anymore. i'm guessing this might be due to an
    > upgrade in gcc (i upgraded from ubuntu 7.10 to 8.04).
    >
    > suppose i have a template class like this:
    >
    > template<typename ValueType,template<typename> class F>
    > struct A{
    > typedef F<ValueType> f_type;
    > };
    >
    > and in a source file I have:
    >
    > typedef A<ValueType,std::vector> a_type;
    >
    > This used to work fine, not anymore:
    >
    > expected a template of type ‘template<class> class F’, got
    > ‘template<class _Tp, class _Alloc> class std::vector’
    >
    > I understand this error message, it's just that _Alloc usually has a
    > default, which previously allowed the definition of A as above, not
    > anymore! I have to refactor my code, any suggestion?
    >

    Bite the bullet and change it! The latest C++ 0x draft standard says
    explicitly that default arguments are not considered.

    You'll want something like:

    template<typename V,template<typename E,
    typename A = std::allocator<E> > class F>

    --
    Ian Collins.
     
    Ian Collins, Aug 25, 2008
    #3
  4. er

    er Guest

    Re: template template parameters with a default - build error thatonce did not occur (new gcc?)

    On Aug 25, 1:22 am, Ian Collins <> wrote:
    > er wrote:
    > > Hi all,

    >
    > > I have some build errors related to template templates that once
    > > compiled fine, but not anymore. i'm guessing this might be due to an
    > > upgrade in gcc (i upgraded from ubuntu 7.10 to 8.04).

    >
    > > suppose i have a template class like this:

    >
    > > template<typename ValueType,template<typename> class F>
    > > struct A{
    > >   typedef F<ValueType> f_type;
    > > };

    >
    > > and in a source file I have:

    >
    > > typedef A<ValueType,std::vector> a_type;

    >
    > > This used to work fine, not anymore:

    >
    > > expected a template of type ‘template<class> class F’, got
    > > ‘template<class _Tp, class _Alloc> class std::vector’

    >
    > > I  understand this error message, it's just that _Alloc usually has a
    > > default, which previously allowed the definition of A as above, not
    > > anymore! I have to refactor my code, any suggestion?

    >
    > Bite the bullet and change it!  The latest C++ 0x draft standard says
    > explicitly that default arguments are not considered.
    >
    > You'll want something like:
    >
    > template<typename V,template<typename E,
    >                              typename A = std::allocator<E> > class F>
    >
    > --
    > Ian Collins.


    OK, thanks!
     
    er, Aug 25, 2008
    #4
    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.

Share This Page