Boost logo

Boost :

From: Daniel James (daniel_at_[hidden])
Date: 2005-03-19 07:24:44


Miro Jurisic wrote:
>>>So what's the advantage of using std::basic_string over, say, std::vector ?
>>
>>reference counting optimization and maybe others, where there is.
>
>
> Reference counting optimization is widely understood to be make performance of
> multi-threaded code worse than some other implementations of basic_string. Can
> name some other reason why basic_string would be a good rep for Unicode strings?
> I can't think of any.

Small string optimisation. ;)

But, whether you use std::string, std::vector, or
manually manage memory, it should be an implementation detail. The
binary representation should probably be exposed by its iterators, not
the std::string. i.e. instead of get_binary_layout(), have:

     binary_iterator binary_begin();
     binary_iterator binary_end();
     const_binary_iterator binary_begin() const;
     const_binary_iterator binary_end() const;

Should you have non-const binary iterators? IMO, yes, anyone who uses
them should know what they're letting themselves in for.

Although, you might want to guarantee that the binary representation is
in continuous memory, and isn't, say, a deque.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk