Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Variadic templates for saving typing (http://www.velocityreviews.com/forums/t950147-variadic-templates-for-saving-typing.html)

Kaba 08-12-2012 02:57 PM

Variadic templates for saving typing
 
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

Melzzzzz 08-12-2012 03:48 PM

Re: Variadic templates for saving typing
 
On Sun, 12 Aug 2012 17:57:08 +0300
Kaba <kaba@nowhere.com> 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;
}


Kaba 08-12-2012 04:46 PM

Re: Variadic templates for saving typing
 
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


All times are GMT. The time now is 04:36 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.