Topic: FW: Implicit type declaration proposals ("let"or "auto") status ?
Author: "Richard Smith" <richard@ex-parrot.com>
Date: Thu, 14 Mar 2002 17:06:41 GMT Raw View
"Igor A. Goussarov" <igusarov@akella.com> wrote in message
news:3C75F9EC.96317A09@akella.com...
> Team Hyer wrote:
> >
> > There's one case no one seems to have mentioned:
> >
> > int i;
> > double z;
> > auto j = i, x = z;
>
> Well... Since "int x, y;" is equivalent to "int x; int y;" I'd like
> the declaration in your example be treated as "auto j = i; auto x = z;"
> Yes, this looks odd because one might expect that j and x are of the
> same type. But 'auto' is not a real _type_ it's a special keyword (or
> whatever).
In that case, how should this be interpreted?
int i;
double z;
auto j = i, *k = &z;
auto *l = i;
I think a general way of dealing with is these problems is by transforming
it to a case that the current language can handle: function template
argument deduction. So for each list of declarations create a function
declaration with an argument for each declarator in the declaration list,
and call each function with the initialiser:
template <class __type_1>
void __decl_1( __type_1 j, __type_1 *k );
__decl_1( i, &z );
template <class __type_2>
void __decl_2( __type_2 *k );
__decl_2( i );
This at least gives a consistent set of rules without requiring lots of new
type deduction rules to be added to the standard. In the above example,
both declaration lists fail: deducing __type_1 fails because the first
argument deduces it as int and the second as double. The second example
fails because i is an int, and cannot match a __type_2 * argument.
I think this is perhaps more useful that deducing the types of j and x (in
your example) independently. This way, if you want to deduce two types
independently, you can just write
auto j = i;
auto x = z;
or if you want the same type to be used,
auto j = i, x = z;
allows you to do that. It seems to me that this gives the programmer more
flexibility. This approach also has the advantage that the decision on
whether j should be an int or an int & are already made using an existing,
working mechanism.
--
Richard Smith
---
[ 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 ]
Author: "Craig Tiller" <ctiller@bigpond.net.au>
Date: Mon, 25 Feb 2002 16:17:50 GMT Raw View
To me that says that j & x should have different types - something that is a
bit different, yes, but it seems to be the lesser of two evils - having to
remember ordering rules to figure if j as a double or if x was an int would
be bad, and trying to make the compiler do promotions so that j and x both
were doubles would trip people up a lot when you're working with classes --
and it would just make people want to write user defined conversions more...
"Team Hyer" <teamhyer@yahoo.com> wrote in message
news:20020219103527.45769.qmail@web12402.mail.yahoo.com...
> There's one case no one seems to have mentioned:
>
> int i;
> double z;
> auto j = i, x = z;
>
> -- Tom Hyer
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Sports - Coverage of the 2002 Olympic Games
> http://sports.yahoo.com
>
> ---
> [ 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 ]
>
---
[ 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 ]
Author: Team Hyer <teamhyer@yahoo.com>
Date: Tue, 19 Feb 2002 23:05:57 GMT Raw View
There's one case no one seems to have mentioned:
int i;
double z;
auto j = i, x = z;
-- Tom Hyer
__________________________________________________
Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games
http://sports.yahoo.com
---
[ 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 ]