Topic: string size() v. length()
Author: Valentin Bonnard <bonnardv@pratique.fr>
Date: 1998/02/19 Raw View
Pete Forman wrote:
>
> CD2 lib.string.capacity defines size() and length() to be synonymous.
> What are the reasons for allowing both, and which is to be preferred.
>
> The arguments for either that I have found are
>
> size: STL containers have size() but no length().
>
> length: On some platforms I use Rogue Wave's RWCString. This has
> length() but no size().
Good question. I even think it should be a FAQ.
Simple: string is at the same time a containner and obey
the RandomAccessibleContainner requirement (in SGI STL speak)
and a traditionnal string
size() belongs to the containner interface and lenght () to
the tradionnal string interface (that is, Plauger's old
non-template string class).
--
Valentin Bonnard mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://www.pratique.fr/~bonnardv/
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Pete Forman <gsez020@compo.bedford.waii.com>
Date: 1998/02/16 Raw View
CD2 lib.string.capacity defines size() and length() to be synonymous.
What are the reasons for allowing both, and which is to be preferred.
The arguments for either that I have found are
size: STL containers have size() but no length().
length: On some platforms I use Rogue Wave's RWCString. This has
length() but no size().
--
Pete Forman
Western Geophysical
pete.forman@bedford.waii.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://reality.sgi.com/austern_mti/std-c++/faq.html ]