|
Boost : |
From: Eric Niebler (eric_at_[hidden])
Date: 2005-01-28 19:14:30
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'
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk