|
Boost : |
From: wb_at_[hidden]
Date: 2002-02-18 18:50:12
David Abrahams <david.abrahams_at_[hidden]> wrote on Mon Feb 18 10:20:48 2002:
| ----- Original Message -----
| From: "Peter Dimov" <pdimov_at_[hidden]>
| To: <boost_at_[hidden]>
|
|
| > From: "Daniel Frey" <daniel.frey_at_[hidden]>
| > >>>
| > I'm reading all those pro-'auto' comments with a little fear. Why it
| > 'auto' really needed if we have a good typeof? Example:
| > <<<
| >
| > It depends on what you consider a 'good' typeof. A typeof that makes it
| easy
| > to do auto/let things (IOW one that strips references and top-level cv
| > qualifiers) isn't a good typeof as far as I'm concerned because it has
| > little value.
| >
| > There's also the fact that when you have to repeat a complex expression
| > twice you will make an error sooner or later. :-)
|
| And along these lines I want the ability to put a typedef /anywhere/ in a
| template declaration after the first argument (this is Walter Brown's idea):
|
| template <class A, typdef some_complicated_expression<A> x; class Y = X&,
| int z>
| struct Foo
| {
| ...
| };
While I appreciate the credit, Dave has actually proposed a slight
extension of my thoughts on this subject.
I was originally motivated by the distasteful and error-prone need to
duplicate some complicated type expressions in several places within a
function template:
template< class T1, class T2, class T3 >
typename complicated_expression<T1,T2,T3>::type
f( T1 const &, ...) {
typedef typename complicated_expression<T1,T2,T3>::type result;
// ...
return typename other_expression<result>::type( ... );
}
Because all I wanted a typedef whose scope was limited to the template
definition, I thought of /appending/ such typedefs to the extant
template parameter declaration list:
template< class T1, class T2, class T3
; typedef complicated_expression<T1,T2,T3>::type result
>
result
f( T1 const &, ... ) {
// ...
return typename other_expression<result>::type( ... );
}
In principle I like the freedom that Dave's extension (to allow the
typedef /amidst/ the template parameters) would bring. However, I
believe that this needs careful thought, lest we introduce confusion as
to the number of template parameters there actually are; it would be
easy to misread such a declaration since, for example, the following
really looks like three parameters at first glance, not the two that are
actually intended:
template< class T1; typedef complicated<T1>::type result; class T3 >
//etc
More importantly, I deliberately don't want such a typedef (anyone have
a good name for this?) to interfere with any template argument type
deduction, etc.
I'm glad to see this aired for additional input; thanks.
- WEB
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk