|
Boost : |
From: Markus Schöpflin (markus.schoepflin_at_[hidden])
Date: 2007-10-12 04:25:45
shunsuke wrote:
> The failures of iterator_range and sub_range.cpp seem to be fixed trivially.
> Wrap string literals with as_literal.
> Am I right?
> Here is a patch.
> http://svn.boost.org/trac/boost/ticket/1302
This patch might fix this particular failure, but I don't think it should
be applied, as it only masks the real problem.
The failure comes from the fact, that range currently is not able to
correctly handle char[] types. For example:
str = "hello world"
rr = make_iterator_range( str.begin(), str.begin() + 5 );
BOOST_CHECK( rr == "hello" );
This fails because rr (length 5) is compared to a char array (length 6), as
the terminating null character is not correctly handled.
In boost/range/detail/implementation_help.hpp there is code that should
deal with this, but it is commented out:
template< class T, std::size_t sz >
inline const T* array_end( const T BOOST_RANGE_ARRAY_REF()[sz] )
{
/*
typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c<
is_same<char,T>::value || is_same<wchar_t,T>::value,
char_or_wchar_t_array_tag, int >::type tag;
return array_end<T,sz>( boost_range_array, tag() );
*/
return boost_range_array + sz;
}
If I enable all the deactivated code in this file, all range tests pass for
me on Tru64/CXX.
Thorsten, is there a reason that prevents you from enabling the deactivated
code? If you lack the time, do you want me the commit the modified header?
(See attached patch.)
Markus
Index: implementation_help.hpp
===================================================================
--- implementation_help.hpp (revision 39918)
+++ implementation_help.hpp (working copy)
@@ -57,7 +57,6 @@
return const_cast<Char*>( str_end( s, s ) );
}
- /*
template< class T, std::size_t sz >
inline T* array_end( T BOOST_RANGE_ARRAY_REF()[sz], int )
{
@@ -81,32 +80,25 @@
{
return boost_range_array + sz - 1;
}
- */
template< class T, std::size_t sz >
inline T* array_end( T BOOST_RANGE_ARRAY_REF()[sz] )
{
- /*
typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< is_same<char,T>::value || is_same<wchar_t,T>::value,
char_or_wchar_t_array_tag,
int >::type tag;
return array_end<T,sz>( boost_range_array, tag() );
- */
- return boost_range_array + sz;
}
template< class T, std::size_t sz >
inline const T* array_end( const T BOOST_RANGE_ARRAY_REF()[sz] )
{
- /*
typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< is_same<char,T>::value || is_same<wchar_t,T>::value,
char_or_wchar_t_array_tag,
int >::type tag;
return array_end<T,sz>( boost_range_array, tag() );
- */
- return boost_range_array + sz;
}
/////////////////////////////////////////////////////////////////////
@@ -119,7 +111,6 @@
return str_end( s ) - s;
}
- /*
template< class T, std::size_t sz >
inline std::size_t array_size( T BOOST_RANGE_ARRAY_REF()[sz], int )
{
@@ -143,31 +134,24 @@
{
return sz - 1;
}
- */
template< class T, std::size_t sz >
inline std::size_t array_size( T BOOST_RANGE_ARRAY_REF()[sz] )
{
- /*
typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< is_same<const char,T>::value || is_same<const wchar_t,T>::value ||
is_same<char,T>::value || is_same<wchar_t,T>::value,
char_or_wchar_t_array_tag,
int >::type tag;
return array_size<T,sz>( boost_range_array, tag() );
- */
- return sz;
}
template< class T, std::size_t sz >
inline std::size_t array_size( const T BOOST_RANGE_ARRAY_REF()[sz] )
{
- /*
typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< is_same<char,T>::value || is_same<wchar_t,T>::value,
char_or_wchar_t_array_tag,
int >::type tag;
return array_size<T,sz>( boost_range_array, tag() );
- */
- return sz;
}
} // 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