Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2005-12-31 10:58:44

Joe Gottman wrote:
> "Eric Niebler" <eric_at_[hidden]> wrote in message
>>There is a bug in Boost.Range that is causing boost::end() to execute a
>>slower code path when called with a string literal. The type of "hello"
>>is char const [6], and end() should be O(1). Indeed, Boost.Range has
>>code to handle just this case, but it never gets called. The problem is
>>the way overload resolution happens between these two functions
>> template< typename T, std::size_t sz >
>> const T* boost_range_end( const T (&array)[sz] )
>> const char* boost_range_end( const char* s )
> These two functions are not equivalent, since strlen("hello") equals 5
> and not 6. Depending on what you are using the range for, you might or
> might not want the '\0' at the end of the string to be part of the range.

When I said, "Boost.Range has code to handle just this case" I meant
that it handles arrays of char and wchar_t to account for the null
termination. So these two functions *are* equivalent in that they both
return the same value. The only difference is one is O(1) and the other
is O(N).

Eric Niebler
Boost Consulting

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