Boost logo

Boost :

From: Pavol Droba (droba_at_[hidden])
Date: 2008-04-04 03:37:04


Mat Marcus wrote:
> On Wed, Apr 2, 2008 at 2:54 PM, Thorsten Ottosen
> <thorsten.ottosen_at_[hidden]> wrote:
>> Mat Marcus skrev:
>>> In 1.34.1 we rely on boost::range::begin/end for const char* . That is
>>> we can invoke something like:
>>> const char* range= "foo";
>>> std::copy(boost::begin(range), boost::end(range), result);
>>> In 1.35.0, under MSVC 9.0, code similar to the above. Are there known
>>> issues with range::end(const char*) in 1.35.0 (e.g. no longer
>>> supported), or do I need to explore further?
>> There are a number of changes to boost.range. I guess they should be
>> written in the "updated libraries" section of the announcement. Is
>> it still possible to update that section, Beman?
>> -Thorsten
> Could you please say a bit more about the rationale for the 1.35
> changes? I have been unable to use the 1.35.0 version of
> boost::begin/end/size on ranges due to failures of the type
> calulcation metacode. Instead I've replaced a number of instances of
> boost::size(some_range) with std::distance(boost::begin(some_range),
> boost::end(some_range)), since the use of - operationstogether with
> the current versions of begin/end causes deduction failures, etc.

If I might toss my few cents, the reason for changes come from an ambiguity in usage of
character literals.

Imagine you have following

char str[] = 'h', 'e', 'l', 'l', 'o', 0;
or simply
char str[] = "hello";

For some algorithms like for-each, it is required, that the range related to this literals
contains the trailing 0. On the other hand, string algorithms require that the leading 0 is
stripped from the range, since it is only a terminator, not a valid data.

To resolve this issue, it was decided to remove implicit support for c-strings altogether and
replace it with an explicit one, using as_array and as_literal helpers.

These helpers convert the C-string to a range, using the specific semantics. as_litaral should
be able to handle also ordinary char* -like strings.

So all you need to do, is to convert your char* range using as_literal.

Best regards,

Boost list run by bdawes at, gregod at, cpdaniel at, john at