[range] patch to fix begin() and end()

The following trivial use of Boost.Range fails to compile: #include <boost/range/begin.hpp> template<class Rng> void foo(Rng const& rng) { boost::begin(rng); } int main() { char* sz = "hello"; foo( sz ); } With g++, I get: $ g++ -I$BOOST_ROOT test.cpp /cygdrive/c/boost/cvs/boost/boost/range/begin.hpp: In function `typename boost::range_const_iterator<C>::type boost::range_detail::begin(const C&) [with C = char*]': /cygdrive/c/boost/cvs/boost/boost/range/begin.hpp:162: instantiated from `typename boost ::range_const_iterator<C>::type boost::begin(const T&) [with T = char*]' test.cpp:6: instantiated from `void foo(const Rng&) [with Rng = char*]' test.cpp:12: instantiated from here /cygdrive/c/boost/cvs/boost/boost/range/begin.hpp:40: error: request for member `begin' in `c', which is of non-aggregate type `char* const' The attached patch fixes the problem for both boost::begin() and boost::end(). I have verified that the range tests pass with this change. -- Eric Niebler Boost Consulting www.boost-consulting.com Index: begin.hpp =================================================================== RCS file: /cvsroot/boost/boost/boost/range/begin.hpp,v retrieving revision 1.11 diff -b -d -u -r1.11 begin.hpp --- begin.hpp 5 Jan 2005 18:19:30 -0000 1.11 +++ begin.hpp 29 Jan 2005 00:07:13 -0000 @@ -111,20 +111,40 @@ return s; } + inline const char* begin( const char*const& s ) + { + return s; + } + inline char* begin( char*& s ) { return s; } + inline char* begin( char*const& s ) + { + return s; + } + inline const wchar_t* begin( const wchar_t*& s ) { return s; } + inline const wchar_t* begin( const wchar_t*const& s ) + { + return s; + } + inline wchar_t* begin( wchar_t*& s ) { return s; } + + inline wchar_t* begin( wchar_t*const& s ) + { + return s; + } #endif } // namespace 'range_detail' Index: end.hpp =================================================================== RCS file: /cvsroot/boost/boost/boost/range/end.hpp,v retrieving revision 1.14 diff -b -d -u -r1.14 end.hpp --- end.hpp 5 Jan 2005 18:19:31 -0000 1.14 +++ end.hpp 29 Jan 2005 00:07:13 -0000 @@ -111,20 +111,40 @@ return range_detail::str_end( s ); } + inline char* end( char*const& s ) + { + return range_detail::str_end( s ); + } + inline wchar_t* end( wchar_t*& s ) { return range_detail::str_end( s ); } + inline wchar_t* end( wchar_t*const& s ) + { + return range_detail::str_end( s ); + } + inline const char* end( const char*& s ) { return range_detail::str_end( s ); } + inline const char* end( const char*const& s ) + { + return range_detail::str_end( s ); + } + inline const wchar_t* end( const wchar_t*& s ) { return range_detail::str_end( s ); } + + inline const wchar_t* end( const wchar_t*const& s ) + { + return range_detail::str_end( s ); + } #endif } // namespace 'range_detail'

"Eric Niebler" <eric@boost-consulting.com> wrote in message news:41FAD566.6080001@boost-consulting.com... | | The following trivial use of Boost.Range fails to compile: | | #include <boost/range/begin.hpp> | | template<class Rng> | void foo(Rng const& rng) | { | boost::begin(rng); | } | | int main() | { | char* sz = "hello"; | foo( sz ); | } Pavol recently the same problem. Our solution was to pass the char* arguments by value. That should be what the current CVS version does. Could you check that your problem has gone away in the cvs version? Thanks -Thorsten

Thorsten Ottosen wrote:
"Eric Niebler" <eric@boost-consulting.com> wrote in message news:41FAD566.6080001@boost-consulting.com... | | The following trivial use of Boost.Range fails to compile: | | #include <boost/range/begin.hpp> | | template<class Rng> | void foo(Rng const& rng) | { | boost::begin(rng); | } | | int main() | { | char* sz = "hello"; | foo( sz ); | }
Pavol recently the same problem. Our solution was to pass the char* arguments by value. That should be what the current CVS version does.
Are you sure? I just sync'ed, and the string versions of begin() and end() still take their arguments by reference. The problem remains. -- Eric Niebler Boost Consulting www.boost-consulting.com

| > Pavol recently the same problem. Our solution was to pass | > the char* arguments by value. That should be what the current CVS version | > does. | > | | | Are you sure? I just sync'ed, and the string versions of begin() and | end() still take their arguments by reference. The problem remains. I get the extract below from the CVS. The newest version should be 1.12 for begin.hpp and 1.15 for end.hpp. Do your version match? -Thorsten $ cvs diff -c -r1.11 -r1.12 begin.hpp nesotto@cvs.sf.net's password: Warning: No xauth data; using fake authentication data for X11 forwarding. Index: begin.hpp =================================================================== RCS file: /cvsroot/boost/boost/boost/range/begin.hpp,v retrieving revision 1.11 retrieving revision 1.12 diff -c -r1.11 -r1.12 *** begin.hpp 5 Jan 2005 18:19:30 -0000 1.11 --- begin.hpp 20 Jan 2005 22:33:24 -0000 1.12 *************** *** 84,90 **** // string ////////////////////////////////////////////////////////////////////// ! #if BOOST_WORKAROUND(__MWERKS__, <= 0x3204 ) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) // CW up to 9.3 and borland have troubles with function ordering inline const char* begin( const char* s ) { --- 84,90 ---- // string ////////////////////////////////////////////////////////////////////// ! #if 1 || BOOST_WORKAROUND(__MWERKS__, <= 0x3204 ) || BOOST_WORKAROUND(__BORLAN DC__, BOOST_TESTED_AT(0x564)) // CW up to 9.3 and borland have troubles with function ordering inline const char* begin( const char* s ) {
participants (2)
-
Eric Niebler
-
Thorsten Ottosen