|
Boost Users : |
From: Bill Lear (rael_at_[hidden])
Date: 2007-07-27 18:07:33
On Friday, July 27, 2007 at 23:33:21 (+0200) Ovanes Markarian writes:
>On Fri, July 27, 2007 23:11, Bill Lear wrote:
>> On Friday, July 27, 2007 at 22:49:22 (+0200) Ovanes Markarian writes:
>>>Most of std classes support custom allocators. basic_stringstream and
>>>vector do this as well. You can preallocate the memory needed and
>>>create objects in this memory locations. For more help see the
>>>placement new operator.
>>
>> Hmm, yes, they do, but they also have a pitfall. If I create a new
>> templated ostringstream with a custom allocator, it then means that
>> the string that is returned also must use this custom allocator,
>> and is incompatible with standard strings. I guess that's not
>> surprising, however, now that I think about it...
>
>I don't think it is so. std::string and a stream class are containers
>of elements. How they contain them is their own beer. They exchange
>them for example via operators << and >> where it is defined how the
>strings are serialized or deserialized to the stream. In these
>operators you provide as template params Elems stored in stream and
>traits about these Elems. And the rest is how you handle it.
Well, stringstream defines a type, from g++ header:
typedef basic_string<char_type, _Traits, _Alloc> __string_type;
and str() is defined to return this:
__string_type str() { ...}
So, if I have a std::string, and an ostringstream with a different
allocator, say my_ostringstream, I cannot do this:
my_ostringstream os;
os << ...;
std::string s = os.str();
Bill
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net