🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

4 total messages Started by Nico Josuttis Tue, 02 Apr 1996 15:16
strings as stl container
#3891
Author: Nico Josuttis
Date: Tue, 02 Apr 1996 15:16
26 lines
1587 bytes
Due to the fact that strings have iterator support,
the could be used as stl container.
But two things are missing:
 - push_back()
 - clear()
These are fundamental operations, that the corresponding "normal"
container, namely vector, has.
Especially push_back() would be essential to use insert iterators
for strings.
Wouldn't it make sense to introduce them for strings ?

--------
Nico                             address: BREDEX GmbH
email:   nico@bredex.de                   Nicolai Josuttis
                                          Fallersleber-Tor-Wall 23
phone:   +49 531 24330-0                  D-38100 Braunschweig
fax:     +49 531 24330-99                 Germany
--------


[ 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         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
Re: strings as stl container
#3914
Author: Joe Buck
Date: Thu, 04 Apr 1996 18:15
62 lines
2531 bytes
Nico Josuttis <nico@bredex.de> writes:
>Due to the fact that strings have iterator support,
>the could be used as stl container.

Correct.

>But two things are missing:
> - push_back()
> - clear()

No, these are not needed.

>These are fundamental operations, that the corresponding "normal"
>container, namely vector, has.

The documentation I have does not list clear as a member of vector.

>Especially push_back() would be essential to use insert iterators
>for strings.

No, this isn't true.  You need push_back to use back_insert_iterator,
but insert_iterator only needs insert, which string does have.

Try the following program (works with gcc 2.7.2/libg++ 2.7.1 and appears
to conform to the standard if I didn't screw up):

----------------------
#include <string>
#include <iterator>
#include <algorithm>

const char text[] = "This is text\n";
const char text2[] = "even more ";

int main()
{
    string foo;
    insert_iterator<string> iter = inserter(foo, foo.begin());
    copy(text, text + sizeof(text)-1, iter);
    cout << "value of foo: " << foo;

    copy(text2, text2 + sizeof(text2)-1, inserter(foo, foo.begin()+8));
    cout << "value of foo: " << foo;
}
----------------------
	 
This prints
value of foo: This is text
value of foo: This is even more text

-- 
-- Joe Buck 	<jbuck@synopsys.com>	(not speaking for Synopsys, Inc)

Work for something because it is good,
not just because it stands a chance to succeed.	   -- Vaclav Havel
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]
Re: strings as stl container
#3925
Author: Nathan Myers, http://www.cantrip...
Date: Fri, 05 Apr 1996 03:36
29 lines
1732 bytes
Joe Buck wrote:

> Nico Josuttis <nico@bredex.de> writes:
> >Due to the fact that strings have iterator support,
> >they could be used as stl container.
>
> >But two things are missing:
> > - push_back()
> > - clear()
> 
> No, these are not needed.

The January '96 WP lists clear() as a required member of 
a Sequence, and push_back() as an optional member to be 
"provided only for the containers for which they take
constant time".  In that version of the WP, some of the
optional members are provided, others are not.  

These omissions probably should be listed as an open issue for 
the Strings chapter.

Nathan Myers
ncm@cantrip.org
---
[ 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         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
Re: strings as stl container
#3987
Author: Nico Josuttis
Date: Thu, 11 Apr 1996 08:09
49 lines
2632 bytes
In article <4jvdnd$c9c@hermes.synopsys.com>,
Joe Buck <jbuck@Synopsys.COM> wrote:
>Nico Josuttis <nico@bredex.de> writes:
>>Due to the fact that strings have iterator support,
>>the could be used as stl container.
>
>Correct.
>
>>But two things are missing:
>> - push_back()
>> - clear()
>
>No, these are not needed.
clear() is required for sequenceable containers,
push_back() is optional for sequenceable containers but would make
many sense.
So for the others vector like operations
(pop_back(), front(), back()).

>
>>These are fundamental operations, that the corresponding "normal"
>>container, namely vector, has.
>
>The documentation I have does not list clear as a member of vector.
>
Oh yes, it does, see 23.2.5.6 in vector class structure.

>>Especially push_back() would be essential to use insert iterators
>>for strings.
>
>No, this isn't true.  You need push_back to use back_insert_iterator,
>but insert_iterator only needs insert, which string does have.
>
But insert_iterators are VERY dangerous for sequenceable collections.
They invalidate themself if the position parameter is not end().
So having push_back() would be safer and of course more convenient
(otherwise there is no sense to have it for vectors either).

-- 
Nico                             address: BREDEX GmbH, Nicolai Josuttis
email:   nico@bredex.de                   Fallersleber-Tor-Wall 23
phone:   +49 531 24330-0                  D-38100 Braunschweig
fax:     +49 531 24330-99                 Germany
---
[ 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         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads