
MB 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 )
The first is O(1) and the second is O(N) becuase it calls strlen. But the second will always be chosen because non-templates are preferred over templates.
I guess that is intentional. See: boost::end("hello\0secret")
I don't think it's intentional. There is explicit code for the handling of arrays of char that is never getting called. Presumably, it's not there just because Thorsten likes to type. :-) Your point is valid, though -- it would lead to inconsistent behavior. We'll have to wait for Thorsten to answer. This may all be moot. I recall Thorsten agreeing to remove direct support for null-terminated strings from Boost.Range and adding a utility for creating a range from a char*.
BTW, '#define foreach BOOST_FOREACH' causes name conflict with Boost.Foreach. :-)
Yup, fixed. Thanks. -- Eric Niebler Boost Consulting www.boost-consulting.com