Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-05-11 06:27:43


Pavol Droba wrote:

> What about introducing str_end() functions. The default implementation
> would fall-back to end(), but it can be overriden for special cases
> (like char[]).
> If we go this way however, we must remove direct suppor for
> null-terminated
> strings like char* and leave it only to str_end(). Since otherwise
> there
> will still be a bit of confusion.
> Naturaly, there will be need for str_size, and possibly str_begin
> (for consistency).

I'd name it strlen, actually. And I wouldn't fall back to end(); a string
type should be marked as such by providing an appropriate overload for
strlen (and strbegin/strend).

> So far it seems easy. But there is a catch as usualy. There are
> generic facilities like FOREACH, that iterate over an arbitrary range.

It would be perfectly reasonable for a language-level foreach to omit the
trailing zero when iterating over a character literal. But I don't think
that this case is possible to detect. I wouldn't be surprised if it is,
though, given the current wizardry in BOOST_FOREACH (somehow exploiting the
fact that literals are const but convertible to char*.)

But this is a special case. In general, when you see char[4] (or
wchar_t[4]), you have absolutely no license to replace the 4 with undefined
behavior.

std::swprintf( buffer, size(buffer), L"%d", i );


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