Boost logo

Boost :

Subject: Re: [boost] Heads up - string_ref landing
From: Yanchenko Maxim (maximyanchenko_at_[hidden])
Date: 2012-11-15 23:47:45


Marshall. low <mclow.lists. at> gmail.com> writes:

> Please let me know what you think!

As probably everyone, we have our own device for this.
Here are some points and experience we gathered.

1. This class is essentially just an iterator_ range<char*> (modulo template for
const/wchar_t), so it should either inherit from it or have corresponding converting
ctors/operators. In this sense Olaf/Gennadiy's remarks are pretty valid. OTOH size
is needed very frequently and having it precomputed is a good thing, so conversion
approach seems to be better (but then we lose passing by reference as
iterator_range, type_traits etc).
I'm not sure what's more important.

2. Given the above, the name is misleading as it's not a reference to std::string.
We use name char_range.

3. It's worth having a static constructor 'literal' (templated with size) to construct
char_ranges from literals - as the compiler knows their size in compile time (minus
zero terminator). It can be a constexpr too.
Same manner - static function 'from_array', embrasing an array of chars in whole,
assuming there is no zero terminator - useful for working with structures
representing messages in char-based protocols with fixed-width fields.

4. (hack) We had to add a member function 'assign' (this is just operator=) to make
boost::tokenizer return char_ranges. I don't like this part at all as it contradicts the
meaning of say std::vector::assign, so I'd prefer another solution, probably in form
of a customization point in boost::tokenizer.

Thanks,
Maxim


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