Topic: object namespaces
Author: brangdon@cix.co.uk (Dave Harris)
Date: Wed, 6 Feb 2002 20:58:26 GMT Raw View
Ken@Alverson.com (Ken Alverson) wrote (abridged):
> > typeof(foo)::iterator i = //...
>
> I didn't even think of that...it's a little wordier, but it does make a
> lot of sense.
Some people have suggested supporting this use of typeof explicitly,
either with a new keyword (eg "let") or by adopting an existing one (eg
"auto").
let i = find(foo.begin(),foo.end(),bar);
auto i = find(foo.begin(),foo.end(),bar);
This avoids the need to repeat the expression whose type we want, a
redundancy that makes maintainance harder. It is also much shorter and
simpler, and it more directly expresses what we want to say.
Personally I think C++ would be more fun to work with if it had either of
these, as well as typeof.
Dave Harris, Nottingham, UK | "Weave a circle round him thrice,
brangdon@cix.co.uk | And close your eyes with holy dread,
| For he on honey dew hath fed
http://www.bhresearch.co.uk/ | And drunk the milk of Paradise."
---
[ 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: "Ken Alverson" <Ken@Alverson.com>
Date: Thu, 7 Feb 2002 18:20:46 GMT Raw View
"Dave Harris" <brangdon@cix.co.uk> wrote in message
news:memo.20020206194742.30665F@brangdon.madasafish.com...
> Ken@Alverson.com (Ken Alverson) wrote (abridged):
> > > typeof(foo)::iterator i = //...
> >
> > I didn't even think of that...it's a little wordier, but it does make a
> > lot of sense.
>
> Some people have suggested supporting this use of typeof explicitly,
> either with a new keyword (eg "let") or by adopting an existing one (eg
> "auto").
>
> let i = find(foo.begin(),foo.end(),bar);
> auto i = find(foo.begin(),foo.end(),bar);
I like it! I hope it or some variant thereof makes it in.
Ken
---
[ 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: google@vandevoorde.com (Daveed Vandevoorde)
Date: Mon, 4 Feb 2002 18:53:44 GMT Raw View
"Ken Alverson" <Ken@Alverson.com> wrote:
> I'm betting this has been discussed before, but I can't find the right set
> of words to look it up in google groups, so here goes. If the issue has
> been beat to death, please just point me at the discussion to read, thanks!
>
> Is there a reason we can't use an object name in place of a type name to
> access typedefs and/or static fields of the type? Asking by example, why
> hasn't this been made valid:
>
> foo::iterator i = find(foo.begin(),foo.end(),bar);
>
> instead of the current:
>
> vector<int>::iterator i = find(foo.begin(),foo.end(),bar);
I suspect this would add a considerable amount of complexity to
the expression-vs-declaration dismabiguation rules. Would you
also allow long expressions in place of foo? Are expressions
evaluated when used as such?
I think the typeof operator is more promising an extension for
this sort of stuff:
typeof(foo)::iterator i = ...
No need to guess whether you're dealing with the beginning of a
declaration, or just an expression.
Daveed
---
[ 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: Michiel.Salters@cmg.nl (Michiel Salters)
Date: Mon, 4 Feb 2002 21:31:51 GMT Raw View
"Ken Alverson" <Ken@Alverson.com> wrote in message news:<a3k83o$aec$1@eeyore.INS.cwru.edu>...
> Is there a reason we can't use an object name in place of a type name to
> access typedefs and/or static fields of the type? Asking by example, why
> hasn't this been made valid:
>
> foo::iterator i = find(foo.begin(),foo.end(),bar);
>
> instead of the current:
>
> vector<int>::iterator i = find(foo.begin(),foo.end(),bar);
>
[SNIP]
> Short of an automatic type specifier, this solves the problem
> in a pretty logical way that looks like it would be (relatively) simple to
> implement. Is it:
>
> - Planned for the next revision!
> - Solves a problem that isn't worth solving?
> - Not high enough priority?
> - Seriously flawed in some manner?
It's a more restricted alternative to
typeof(foo)::iterator i = //...
__typeof() is an (experimental?) extension of GCC, and
possibly other compilers. It can be used in more situations.
If introduced for these situations, it takes away or diminishes
most of the advantages of your solutions, IMO.
Regards,
--
Michiel Salters
---
[ 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: "Ken Alverson" <Ken@Alverson.com>
Date: Tue, 5 Feb 2002 20:46:16 GMT Raw View
"Michiel Salters" <Michiel.Salters@cmg.nl> wrote in message
news:cefd6cde.0202041211.1ed93279@posting.google.com...
>
> It's a more restricted alternative to
>
> typeof(foo)::iterator i = //...
I didn't even think of that...it's a little wordier, but it does make a lot
of sense. Thanks to those who responded!
Ken
---
[ 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: "Ken Alverson" <Ken@Alverson.com>
Date: Mon, 4 Feb 2002 02:05:35 GMT Raw View
I'm betting this has been discussed before, but I can't find the right set
of words to look it up in google groups, so here goes. If the issue has
been beat to death, please just point me at the discussion to read, thanks!
Is there a reason we can't use an object name in place of a type name to
access typedefs and/or static fields of the type? Asking by example, why
hasn't this been made valid:
foo::iterator i = find(foo.begin(),foo.end(),bar);
instead of the current:
vector<int>::iterator i = find(foo.begin(),foo.end(),bar);
If the type of foo ever changes, the second version breaks but the first
wouldn't. I know the break is trivial to fix, and I know typedef's can
mitigate the problem, but even then if foo changed to a different typedef
the code would break. The first version would tightly bind the iterator
type to the type of the container, which as far as I can tell would be a
good thing. Short of an automatic type specifier, this solves the problem
in a pretty logical way that looks like it would be (relatively) simple to
implement. Is it:
- Planned for the next revision!
- Solves a problem that isn't worth solving?
- Not high enough priority?
- Seriously flawed in some manner?
Ken
---
[ 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: Olaf Krzikalla <Entwicklung@reico.de>
Date: Mon, 4 Feb 2002 12:34:21 GMT Raw View
Hi,
Ken Alverson wrote:
> Is there a reason we can't use an object name in place of a type name to
> access typedefs and/or static fields of the type? Asking by example, why
> hasn't this been made valid:
I have asked myself about this point several times, too. In fact, if you
treat a typedef inside a class similiar to a static member, there seems
no reason to not allow things like
v.iterator i = v.begin();
I guess, the next standard will contain several ways to compute a type
from an expression. This one could be useful.
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.research.att.com/~austern/csc/faq.html ]