Topic: }template varargs
Author: "Richard Smith" <richard@ex-parrot.com>
Date: 14 Mar 02 06:04:29 GMT Raw View
"Dylan Nicholson" <dylan@moldflow.com> wrote in message
news:156b8737.0203121808.41a8920c@posting.google.com...
> This is been brought up many times before but I was just wondering
> what ideas were floating about and whether something like this was
> likely to make it into a future revision.
>
> Basically the problem seems to be one of notation.
[ ... ]
> You could imagine a syntax like
>
> template <...>
> void foo(...)
> {
> /* ... */
> bar(...);
> /* ... */
> }
I think I would prefer a way of naming the arguments, otherwise you can
imagine that you might get into trouble with more complicated nested types
template <...>
struct foo
{
template <...> // The same ...? A different one?
struct bar
{
};
};
Maybe a new keyword could be introduced, e.g.
template <typelist L>
void foo( L l )
{
/* ... */
bar( l );
/* ... */
}
In the function call foo( 1, 2 ), what type is L? Perhaps something like
typelist<int, int>. And typelist<int, int> needs an implicit constructor
that takes a pair of integers, and a conversion operator that returns a pair
of integers. A syntax like this might be quite nice. It would give
typelist the syntactical appearance of a template class, even though it
needs quite a lot of compiler support to do things like the implicit
conversions. In pseudo-code, typelist could look something like
template < class T1, class T2, ... >
struct typelist
{
public:
implicit typelist( T1, T2, ...);
operator { T1, T2, ... }();
typedef T1 /*or void*/ car_type;
typedef typelist<T2, ...> /*or void*/ cdr_type;
car_type car();
cdr_type cdr();
};
I think a framework like this would allow you to get at all of the compile
time functionality that, say,
the Loki typelist exposes.
template < typelist L >
struct typelist_size
{
static const size_t value
= typelist_size< L::cdr_type >::value + 1;
};
template <>
struct typelist_size<void>
{
static const size_t value = 0;
};
Or even better,
template < typelist L >
static const size_t typelist_size
= typelist_size< L::cdr_type > + 1;
template <>
static const size_t typelist_size<void> = 0;
--
Richard Smith
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
[ 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.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]