Topic: Pre-Redmond Mailing: some thoughts to 1704 & 1706
Author: Olaf Krzikalla <Entwicklung@reico.de>
Date: Tue, 28 Sep 2004 15:35:52 GMT Raw View
Hi all,
N1706 Opaque Typedefs:
I appreciate this proposal, but I strongly miss a point or at least a
discussion about forwarding typedefs. IMHO forwarded typedefs are an
important motivation for
the introduction of opaque typedefs. Also, how are opaque typedefs
related to ADL (esp. what would happen in the introductory examples of
N1691 Explicit Namespaces, if opaque typedefs were used)?
N1704 Variadic Templates: Exploring the Design Space:
1. Why is it necessary to denote the tuple inside the definiton of the
class/function with its name and the trailing ellipsis? Why isn't the
name sufficent (I think it is)? The examples in 3.1. could be rewritten:
template<typename Head, ... Tail> struct tuple { // #1
Head head;
tuple <Tail> tail;
};
template<typename T, ... Elements>
struct adjacent_find : adjacent_find<Elements> { };
template<... Args> void printf(const char* s, const Args& args);
This would not only cleaning up the syntax a little bit, but also makes
teaching easier (otherwise you have to explain somehow, why in 3.2.
neither 'Elements' nor 'elements' needs the trailing ellipsis, even if
they are tuples).
2. If my first point is somehow accepted, then the next question arises:
why should we stick with the clunky ellipses syntax at all? Why not just
introduce a new keyword 'tuple<>' (or something similar) instead, that
may appear only as a template argument.
tuple<class> and tuple<typename> are interchangeable and denote a tuple
of types (the common use).
tuple<int>, tuple<const char*> etc. denote a tuple of constant integral
expressions evaluated at compile time.
Note, that with this syntax we could mix different tuples in one
template argument list:
template<tuple<class> types, tuple<int> inits>
class example;
example<int, double, 1, 2, 3>; // legal
example<int, 2, double, 4>; // illegal
Or we can do something like this:
template<tuple<class> typelist1, int separator, tuple<class> typelist2>
class two_typelists;
3. 3.7 only explains the unpacking of a value from a parameter pack. Why
shouldn't it be possible to unpack a type directly rather than relying
on decltype:
template<tuple<class> Args>
void f(Args args)
{
// Make copy of 2nd argument
Args<1> second = args[1]; //Args<N> denotes the N'th type
}
For tuple<int> this could become the only way to extract a certain
value:
template<tuple<int> Args>
void f ()
{
std::cout << Args<1>;
}
// prints '2':
f<1,2,3>();
4. Maybe the usefulness of tuples wrt default template paramters should
be mentioned:
//a compatible way to use STL containers as template template
parameters:
template< template<tuple<class>> std_container, class T>
class example {
typedef typename std_container<T>::const_iterator some_type;
//etc.
};
Best regards
Olaf Krzikalla
---
[ 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 ]