Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2005-12-31 11:04:04


Daniel Frey wrote:
> Eric Niebler wrote:
>
>>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 )
>
>
> I think something like
>
> template< typename T >
> enable_if< is_same< T, char >, const char* >::type
> boost_range_end( const T* s )
>
> for the second overload should fix it.
>

That only works on compilers that handle SFINAE. Probably the easiest
thing would be to remove the char* overloads and modify the "primary"
boost_range_end(T const &) overload, which currently only works when T
is an STL container, to use is_pointer<T> to dispatch to str_end().

-- 
Eric Niebler
Boost Consulting
www.boost-consulting.com

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