Variadic templates for saving typing

Discussion in 'C++' started by Kaba, Aug 12, 2012.

  1. Kaba

    Kaba Guest

    Hmm.. Should this compile in C++11 (the compiler at Ideone does not)?

    template <typename A, typename B>
    class C {};

    template <typename... TypeSet>
    void f(const C<TypeSet...>& c) {}

    int main()
    {
    C<int, int> c;
    f(c);
    return 0;
    }

    The idea is to save typing in case I'm not interested in the actual
    template-arguments of C.

    --
    http://kaba.hilvi.org
     
    Kaba, Aug 12, 2012
    #1
    1. Advertising

  2. Kaba

    Melzzzzz Guest

    On Sun, 12 Aug 2012 17:57:08 +0300
    Kaba <> wrote:

    > Hmm.. Should this compile in C++11 (the compiler at Ideone does not)?
    >
    > template <typename A, typename B>
    > class C {};
    >
    > template <typename... TypeSet>
    > void f(const C<TypeSet...>& c) {}
    >
    > int main()
    > {
    > C<int, int> c;
    > f(c);
    > return 0;
    > }
    >
    > The idea is to save typing in case I'm not interested in the actual
    > template-arguments of C.
    >


    This works:
    template <typename A, typename B>
    class C {};

    template <template <class...> class C,typename... TypeSet>
    void f(const C<TypeSet...>& c) {}

    int main()
    {
    C<int, int> c;
    f(c);
    return 0;
    }
     
    Melzzzzz, Aug 12, 2012
    #2
    1. Advertising

  3. Kaba

    Kaba Guest

    12.8.2012 18:48, Melzzzzz kirjoitti:
    > This works:
    > template <typename A, typename B>
    > class C {};
    >
    > template <template <class...> class C,typename... TypeSet>
    > void f(const C<TypeSet...>& c) {}
    >
    > int main()
    > {
    > C<int, int> c;
    > f(c);
    > return 0;
    > }


    True, but it matches more than it should:)

    --
    http://kaba.hilvi.org
     
    Kaba, Aug 12, 2012
    #3
    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. Colin Walters
    Replies:
    2
    Views:
    544
    Ben Pfaff
    Feb 13, 2004
  2. Ross A. Finlayson
    Replies:
    19
    Views:
    652
    Keith Thompson
    Mar 10, 2005
  3. Replies:
    2
    Views:
    368
    Dave Thompson
    Feb 27, 2006
  4. Replies:
    5
    Views:
    385
  5. JimLad
    Replies:
    0
    Views:
    525
    JimLad
    Jan 26, 2010
Loading...

Share This Page