|
Boost : |
From: jrb_hobe (jbandela_at_[hidden])
Date: 2002-02-20 14:50:57
In addition to the the semantics of auto mentioned in the previous
post, I would also like to see the it allowed in template parameters.
When in a template paremeter, the compiler would insert the type of
the expression as the template parameter.
For example.
template<auto typename T>
struct MyTemplate{
static T do_something(){...}
};
Given the above template, the following would be equivalent;
int a;
a = MyTemplate<a>::do_something();
a = MyTemplate<int>::do_something();
An advantage of this, is that we could implement typeof trivially
without introducing a new keyword. For example.
template<auto typename T>
struct TypeOf{
typedef T type;
};
And it would be used like this.
template<class T, class S>
TypeOf<( *((T*)0) + *((S*)0) )>::type plus(T &t, S &s)
{ return t+s; }
Regards,
John R. Bandela
--- In boost_at_y..., "Herb Sutter" <hsutter_at_a...> wrote:
> Gary wrote:
> > "Auto" for type deduction.
>
> > Yet another call for "auto" and that's for use in
> > teaching:
>
> Good points. Then:
>
> > typeof
> >
> > Lambda needs to be able to deduce the type of an expression.
> >
> > template<class T, class S>
> > WHAT_IS_THIS_TYPE? operator+(T &t, S &s)
> > { return t+s; }
> >
> > so we need something of the order of:
> >
> > template<class T, class S>
> > typeof(S + T) operator+(T &t, S &s)
> > { return t+s; }
>
> (Note the typo above: "typeof(S+T)" vs. "return t+s;".)
>
> Why not use "auto" here? It would avoid the typo too:
>
> template<class T, class S>
> auto operator+(T &t, S &s)
> { return t+s; }
>
> If different branches would return different things, well, we
already have a
> rule about that sort of type compatibility for the ?: operator.
>
> Herb
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk