Boost logo

Boost :

From: Yitzhak Sapir (ysapir_at_[hidden])
Date: 2002-02-20 15:56:47


Would you really need this? Maybe I don't understand this, have missed
messages in this thread that would make it clear, or see a problem where
there isn't one, but does it have a way around the following particular
problem:

Given:
template <auto typename T> struct Temp {
        static T temp() {}
};
template <> struct Temp<char> {
        static wchar_t temp() {}
};

how would this evaluate?
wchar_t a;
a = MyTemplate<a>::temp();

And besides, just like you could use auto in this manner to implement
typeof(), you could use typeof()to implement this (using your example):
int a;
a = MyTemplate<typeof(a)>::do_something();

or using the simplest auto so far proposed

auto a = MyTemplate<int>::do_something();

I am not sure auto needs to be extended any more than the use in this
last example. Maybe most of the suggestions proposed could be
implemented with this simple "auto VariableName = SomeExpression;"
definition, and it would do best to think up how to implement them this
way than to propose some rather extensive definitions of auto.

> -----Original Message-----
> From: jrb_hobe [mailto:jbandela_at_[hidden]]
> Sent: Wednesday, February 20, 2002 9:51 PM
> To: boost_at_[hidden]
> Subject: [boost] Re: Most needed/desired features in C++
>
>
> 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
>
>
> Info: http://www.boost.org Send unsubscribe requests to:
<mailto:boost-unsubscribe_at_[hidden]>

Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk