Topic: What about operator-> for STL iterators?
Author: c.r.wood@gte.net.no_spam ("Charles Wood")
Date: Fri, 28 Feb 2003 19:04:40 +0000 (UTC) Raw View
"Fred Ma" <fma@doe.carleton.ca> wrote in message
news:3E5E4A2F.D328D3D7@doe.carleton.ca...
: Hello,
:
: I use containers of containers alot. I end up doing this alot:
:
: SomeAlgorithm(
: SomeContainer::Iterator SCI=(*SomeCollection).begin(),
: SCI != (*SomeCollection).end(), ++SCI
: )
Whoa, hang on. Last post is bad.
Post some compilable code please. Thanks... Your code is missing to
much for me to infer the problem.
<snip>
: Fred
:
: ---
: [ 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.jamesd.demon.co.uk/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.jamesd.demon.co.uk/csc/faq.html ]
Author: Ken@Alverson.net ("Ken Alverson")
Date: Fri, 28 Feb 2003 21:38:46 +0000 (UTC) Raw View
"Fred Ma" <fma@doe.carleton.ca> wrote in message
news:3E5E4A2F.D328D3D7@doe.carleton.ca...
>
> Would it be a problem to define operator->() for STL?
> It only saves one character, but it does look a bit more
> natural:
>
> SomeAlgorithm(
> SomeContainer::Iterator SCI=SomeCollection->begin(),
> SCI != SomeCollection->end(), ++SCI
> )
> { // Do something.... }
Am I missing something? I can already do:
vector<int>* vp = new vector<int>(5,10);
copy( vp->begin(), vp->end(),
ostream_iterator<int>(cout,"\n") );
delete vp;
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.jamesd.demon.co.uk/csc/faq.html ]
Author: c.r.wood@gte.net.no_spam ("Charles Wood")
Date: Fri, 28 Feb 2003 21:39:28 +0000 (UTC) Raw View
"Fred Ma" <fma@doe.carleton.ca> wrote in message
news:3E5E4A2F.D328D3D7@doe.carleton.ca...
: Hello,
:
<snip>
: Would it be a problem to define operator->() for STL?
: It only saves one character, but it does look a bit more
: natural:
:
: SomeAlgorithm(
: SomeContainer::Iterator SCI=SomeCollection->begin(),
: SCI != SomeCollection->end(), ++SCI
: )
: { // Do something.... }
:
: Asterisks and round brackets are overused, so they just
: become part of the noise....camouflage, so to speak.
: The "->" shows an much more connected-looking
: connection between the pointed object and the
: member. A bit whimsical, but I suspect the above
: coding is far from rare.
Most newer compiler support this already. Typically access to an
iterator to get at the elements can be done via:
iterator->item;
Some old compilers (the one I use) don't support that. For
compatibility, (*asdf).fdsa is more portable, but less readable.
:
: Fred
:
: ---
: [ 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.jamesd.demon.co.uk/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.jamesd.demon.co.uk/csc/faq.html ]
Author: fma@doe.carleton.ca (Fred Ma)
Date: Fri, 28 Feb 2003 17:50:39 +0000 (UTC) Raw View
Hello,
I use containers of containers alot. I end up doing this alot:
SomeAlgorithm(
SomeContainer::Iterator SCI=(*SomeCollection).begin(),
SCI != (*SomeCollection).end(), ++SCI
)
{ // Do something.... }
Would it be a problem to define operator->() for STL?
It only saves one character, but it does look a bit more
natural:
SomeAlgorithm(
SomeContainer::Iterator SCI=SomeCollection->begin(),
SCI != SomeCollection->end(), ++SCI
)
{ // Do something.... }
Asterisks and round brackets are overused, so they just
become part of the noise....camouflage, so to speak.
The "->" shows an much more connected-looking
connection between the pointed object and the
member. A bit whimsical, but I suspect the above
coding is far from rare.
Fred
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
Author: jdennett@acm.org (James Dennett)
Date: Fri, 28 Feb 2003 19:00:31 +0000 (UTC) Raw View
Fred Ma wrote:
> Hello,
>
> I use containers of containers alot. I end up doing this alot:
>
> SomeAlgorithm(
> SomeContainer::Iterator SCI=(*SomeCollection).begin(),
> SCI != (*SomeCollection).end(), ++SCI
> )
> { // Do something.... }
>
> Would it be a problem to define operator->() for STL?
No. In fact, it was done back in the 20th century.
> It only saves one character, but it does look a bit more
> natural:
>
> SomeAlgorithm(
> SomeContainer::Iterator SCI=SomeCollection->begin(),
> SCI != SomeCollection->end(), ++SCI
> )
> { // Do something.... }
>
> Asterisks and round brackets are overused, so they just
> become part of the noise....camouflage, so to speak.
> The "->" shows an much more connected-looking
> connection between the pointed object and the
> member. A bit whimsical, but I suspect the above
> coding is far from rare.
As a workaround for flawed compilers or libraries, maybe.
Input iterators (or better) as defined by the C++ Standard
already support operator-> -- see Table 72 in 24.1.1 for
the definition of operator->, which says that for an input
iterator ii, ii->m is equivalent to (*ii).m
While I don't see a similar definition for mere output
iterators, all standard containers provide iterators which
support operator->.
Possibly an update to your library or compiler is in order,
if that is possible.
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]