Topic: how to define a template function with a templatized parameter
Author: cpdaniel@pacbell.net ("Carl Daniel")
Date: Wed, 25 Sep 2002 16:20:30 +0000 (UTC) Raw View
"Richard Smith" <richard@ex-parrot.com> wrote in message
news:3D918C6B.7000302@ex-parrot.com...
> DR #150 [http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_closed.html#150]
> raises this particular issue with the example
>
> template <class T, class U = int>
> class ARG { };
>
> template <class X, template <class Y> class PARM>
> void f(PARM<X>) { } // specialization permitted?
>
> void g() {
> ARG<int> x; // actually ARG<int, int>
> f(x); // does ARG (2 parms, 1 with default)
> // match PARM (1 parm)?
>
> which is effectively the same issue. This was closed 'Not A Defect', in
> October '99 with the rationale,
>
> Template template parameters are intended to be handled analogously
> to function function parameters. Thus the number of parameters in a
> template template argument must match the number of parameters in a
> template template parameter, regardless of whether any of those
> paramaters have default arguments or not. [...]
Yeah. I think the committee made a very poor choice there by choosing to
disambiguate the language towards the less useful interpretation. It's
interesting to note that a number of compilers have accepted the more
liberal and useful interpretation that says that template-template
parameters have to be "call compatible", using the analogy of calling a
function, rather than taking the address of a function. IMO, this is the
more intuitive intepretation as well, since "we all know" that templates are
a compile-time facility, and any analogy between template parameters and
function pointers is grossly aritificial.
I've never heard any implementation argument that says that the more liberal
interpretation is harder to implement, or less safe to use - perhaps there
is one when export in considered.?
-cd
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: jrowe@optech.com (john)
Date: Mon, 23 Sep 2002 05:10:13 +0000 (UTC) Raw View
Can someone tell if it is possible and if so how to declare a template
function that has a template
parameter that is an instance of a template class. I would like to
create a function that would
take a container class and a type as specified template types. Whether
this is is efficient, good
form, impractical or not I am not concerned. I am just interested in
whether it can be done and
if so how.
I tried something simple like
template <class C, class T> void foo( C<T> & cont);
or
template < template<class T> class C> > void foo ( C<T>& cont);
but these didn't cut it.
any constructive feedback would be appreciated.
thanks for your help
john
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: anthwil@nortelnetworks.com ("Anthony Williams")
Date: Mon, 23 Sep 2002 11:41:25 +0000 (UTC) Raw View
jrowe@optech.com (john) writes:
> Can someone tell if it is possible and if so how to declare a template
> function that has a template
> parameter that is an instance of a template class. I would like to
> create a function that would
> take a container class and a type as specified template types. Whether
> this is is efficient, good
> form, impractical or not I am not concerned. I am just interested in
> whether it can be done and
> if so how.
template< template<class> class C,class T> void foo(C<T>& const);
The args of the template template-parameter are just to specify whether the
allowed templates have type or non-type parameters, and how many --- their
names are ignored.
Anthony
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: francis.glassborow@ntlworld.com (Francis Glassborow)
Date: Mon, 23 Sep 2002 14:37:46 +0000 (UTC) Raw View
In article <ptv5f3ag.fsf@nortelnetworks.com>, Anthony Williams
<anthwil@nortelnetworks.com> writes
>jrowe@optech.com (john) writes:
>
>> Can someone tell if it is possible and if so how to declare a template
>> function that has a template
>> parameter that is an instance of a template class. I would like to
>> create a function that would
>> take a container class and a type as specified template types. Whether
>> this is is efficient, good
>> form, impractical or not I am not concerned. I am just interested in
>> whether it can be done and
>> if so how.
>
>template< template<class> class C,class T> void foo(C<T>& const);
>
>The args of the template template-parameter are just to specify whether the
>allowed templates have type or non-type parameters, and how many --- their
>names are ignored.
However, in order to do it you need a compiler that handles template
template parameters.
--
Francis Glassborow ACCU
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: kuyper@wizard.net ("James Russell Kuyper Jr.")
Date: Mon, 23 Sep 2002 16:22:47 +0000 (UTC) Raw View
john wrote:
>
> Can someone tell if it is possible and if so how to declare a template
> function that has a template
> parameter that is an instance of a template class. I would like to
> create a function that would
> take a container class and a type as specified template types. Whether
> this is is efficient, good
> form, impractical or not I am not concerned. I am just interested in
> whether it can be done and
> if so how.
>
> I tried something simple like
>
> template <class C, class T> void foo( C<T> & cont);
That syntax recognises C only as a class, not as a template, so C<T>
isn't legal syntax.
> or
> template < template<class T> class C> > void foo ( C<T>& cont);
The problem with that syntax is that the T isn't itself a template
parameter; it's purely a place holder, like the 'd' in the following
declaration:
void bar(void (*f)(double d) );
Try this instead:
template < template<class> class C, class T> void foo(C<T> & const);
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]