|
ALINK="#ff0000">
sequence_buffer<Container, buf_sz>
DescriptionSequence_buffer is similar to back_insert_iterator: it is an output iterator adaptor that appends elements to the end of a container.The main difference between sequence_buffer and back_insert_iterator is that back_insert_iterator inserts elements into a sequence one element at a time; sequence_buffer, however, as the "buffer" part of the name suggests, accumulates elements into a buffer and appends the entire buffer in a single operation. Specifically, the expression *it = v adds v to the end of it's internal buffer. The buffer is automatically flushed when it gets full, or when it is destroyed; flushing the buffer means emptying it and appending its contents to it's underlying container. (It is also possible to flush the buffer manually, by invoking the flush() member function.) This difference has two implications. First, sequence_buffer is only useful if appending an array of N elements is much more efficient than inserting a single element N times. Second, sequence_buffer assumes that it can insert elements at the end of a container using an append member function. This member function is not part of the Container or Sequence requirements. The sequence_buffer adaptor can be used with rope, but not with any of the other containers in the library. (This is the reason why sequence_buffer is defined in the file rope.h, instead of in iterator.h.) If you want to build up a string one character at a time, it is much more efficient to use sequence_buffer than to repeatedly add single characters to the end of a rope. Exampleint main() { const char* const s = "this is a test"; const int N = strlen(s); crope r; transform(s, s + N, sequence_buffer<crope>(r), toupper); cout << "r = " << r << endl; } DefinitionDefined in the header rope, and in the backward-compatibility header rope.h. The sequence_buffer class, and the rope header, are SGI extensions; they are not part of the C++ standard.Template parameters
Model ofOutput Iterator.Type requirements
Public base classesoutput_iteratorMembers
New membersThese members are not defined in the Output Iterator requirements, but are specific to sequence_buffer.
Notes[1] Despite the name "sequence_buffer", this adaptor cannot actually be used with arbitrary sequences: it requires that the template argument Container have an append member function that can insert multiple elements at the end of the container. This member function is not part of the Sequence requirements. This means that sequence_buffer can be used with rope, but not with any of the other predefined container classes. [2] Note how assignment through a sequence_buffer is implemented. In general, unary operator* must be defined so that it returns a proxy object, where the proxy object defines operator= to perform the output operation. In this case, for the sake of simplicity, the proxy object is the sequence_buffer itself. That is, *i simply returns i, and *i = t is equivalent to i = t. You should not, however, rely on this behavior. It is an implementation detail, and it is not guaranteed to remain the same in future versions. See alsoOutput Iterator, rope, front_insert_iterator, back_insert_iterator, insert_iteratorCopyright © 1999 Silicon Graphics, Inc. All Rights Reserved. TrademarkInformation
|