forked from boostorg/range
v2 upgrade
[SVN r34011]
This commit is contained in:
146
test/string.cpp
146
test/string.cpp
@ -17,7 +17,10 @@
|
||||
# pragma warn -8057 // unused argument argc/argv in Boost.Test
|
||||
#endif
|
||||
|
||||
#include <boost/range.hpp>
|
||||
#include <boost/range/as_array.hpp>
|
||||
#include <boost/range/as_literal.hpp>
|
||||
#include <boost/range/functions.hpp>
|
||||
#include <boost/range/metafunctions.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/type_traits.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
@ -26,36 +29,66 @@
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
|
||||
template< class T >
|
||||
inline BOOST_DEDUCED_TYPENAME boost::range_iterator<T>::type
|
||||
str_begin( T& r )
|
||||
{
|
||||
return boost::begin( as_literal(r) );
|
||||
}
|
||||
|
||||
template< class T >
|
||||
inline BOOST_DEDUCED_TYPENAME boost::range_iterator<T>::type
|
||||
str_end( T& r )
|
||||
{
|
||||
return boost::end( as_literal(r) );
|
||||
}
|
||||
|
||||
template< class T >
|
||||
inline BOOST_DEDUCED_TYPENAME boost::range_size<T>::type
|
||||
str_size( const T& r )
|
||||
{
|
||||
return boost::size( as_literal(r) );
|
||||
}
|
||||
|
||||
template< class T >
|
||||
inline bool
|
||||
str_empty( T& r )
|
||||
{
|
||||
return boost::empty( as_literal(r) );
|
||||
}
|
||||
|
||||
template< typename Container, typename T >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
find( Container& c, T value )
|
||||
{
|
||||
return std::find( boost::begin( c ), boost::end( c ), value );
|
||||
return std::find( str_begin(c), str_end(c),
|
||||
value );
|
||||
}
|
||||
|
||||
template< typename Container, typename T >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_const_iterator<Container>::type
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<const Container>::type
|
||||
find( const Container& c, T value )
|
||||
{
|
||||
return std::find( boost::begin( c ), boost::end( c ), value );
|
||||
return std::find( str_begin(c), str_end(c),
|
||||
value );
|
||||
}
|
||||
|
||||
template< typename Container, typename T >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
find_mutable( Container& c, T value )
|
||||
{
|
||||
boost::size( c );
|
||||
boost::end( c );
|
||||
return std::find( boost::begin( c ), boost::end( c ), value );
|
||||
{
|
||||
str_size( c );
|
||||
return std::find( str_begin(c), str_end(c),
|
||||
value );
|
||||
}
|
||||
|
||||
template< typename Container, typename T >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_const_iterator<Container>::type
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<const Container>::type
|
||||
find_const( const Container& c, T value )
|
||||
{
|
||||
boost::size( c );
|
||||
boost::end( c );
|
||||
return std::find( boost::begin( c ), boost::end( c ), value );
|
||||
str_size( c );
|
||||
return std::find( str_begin(c), str_end(c),
|
||||
value );
|
||||
}
|
||||
|
||||
|
||||
@ -72,62 +105,66 @@ void check_char()
|
||||
{
|
||||
typedef char* char_iterator_t;
|
||||
typedef char char_array_t[10];
|
||||
const char* char_s = "a string";
|
||||
char my_string[] = "another string";
|
||||
const unsigned my_string_length = 14;
|
||||
char* char_s2 = "a string";
|
||||
const char* char_s = "a string";
|
||||
char my_string[] = "another string";
|
||||
const char my_const_string[] = "another string";
|
||||
const unsigned my_string_length = 14;
|
||||
char* char_s2 = "a string";
|
||||
|
||||
BOOST_STATIC_ASSERT(( is_same< range_value<char_iterator_t>::type,
|
||||
detail::iterator_traits<char_iterator_t>::value_type>::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< range_iterator<char_iterator_t>::type, char_iterator_t >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< range_const_iterator<char_iterator_t>::type, const char* >::value ));
|
||||
|
||||
BOOST_STATIC_ASSERT(( is_same< range_difference<char_iterator_t>::type,
|
||||
::std::ptrdiff_t >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< range_size<char_iterator_t>::type, std::size_t >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< range_result_iterator<char_iterator_t>::type, char_iterator_t >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< range_result_iterator<const char*>::type, const char* >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< range_iterator<char_iterator_t>::type, char_iterator_t >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< range_iterator<const char*>::type, const char* >::value ));
|
||||
|
||||
BOOST_STATIC_ASSERT(( is_same< range_value<char_array_t>::type,
|
||||
char>::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< range_iterator<char_array_t>::type, char* >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< range_const_iterator<char_array_t>::type, const char* >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< range_iterator<const char_array_t>::type, const char* >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< range_difference<char_array_t>::type,
|
||||
::std::ptrdiff_t >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< range_size<char_array_t>::type, std::size_t >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< range_result_iterator<char_array_t>::type, char* >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< range_result_iterator<const char_array_t>::type, const char* >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< range_iterator<char_array_t>::type, char* >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< range_iterator<const char_array_t>::type, const char* >::value ));
|
||||
|
||||
BOOST_CHECK_EQUAL( begin( char_s ), char_s );
|
||||
std::size_t sz = size( char_s );
|
||||
const char* end1 = begin( char_s ) + sz;
|
||||
BOOST_CHECK_EQUAL( end( char_s ), end1 );
|
||||
BOOST_CHECK_EQUAL( empty( char_s ), (char_s == 0 || char_s[0] == char()) );
|
||||
BOOST_CHECK_EQUAL( str_begin( char_s ), char_s );
|
||||
std::size_t sz = str_size(char_s);
|
||||
const char* str_end1 = str_begin( char_s ) + sz;
|
||||
BOOST_CHECK_EQUAL( str_end( char_s ), str_end1 );
|
||||
BOOST_CHECK_EQUAL( str_empty( char_s ), (char_s == 0 || char_s[0] == char()) );
|
||||
BOOST_CHECK_EQUAL( sz, std::char_traits<char>::length( char_s ) );
|
||||
/*
|
||||
BOOST_CHECK_EQUAL( begin( char_s2 ), char_s2 );
|
||||
BOOST_CHECK_EQUAL( str_begin( char_s2 ), char_s2 );
|
||||
std::size_t sz2 = size( char_s2 );
|
||||
const char* end12 = begin( char_s2 ) + sz;
|
||||
BOOST_CHECK_EQUAL( end( char_s2 ), end12 );
|
||||
const char* str_end12 = str_begin( char_s2 ) + sz;
|
||||
BOOST_CHECK_EQUAL( str_end( char_s2 ), str_end12 );
|
||||
BOOST_CHECK_EQUAL( empty( char_s2 ), (char_s2 == 0 || char_s2[0] == char()) );
|
||||
BOOST_CHECK_EQUAL( sz2, std::char_traits<char>::length( char_s2 ) );
|
||||
*/
|
||||
BOOST_CHECK_EQUAL( begin( my_string ), my_string );
|
||||
range_iterator<char_array_t>::type end2 = begin( my_string ) + size( my_string );
|
||||
range_iterator<char_array_t>::type end3 = end( my_string );
|
||||
BOOST_CHECK_EQUAL( end3, end2 );
|
||||
BOOST_CHECK_EQUAL( empty( my_string ), (my_string == 0 || my_string[0] == char()) );
|
||||
BOOST_CHECK_EQUAL( size( my_string ), my_string_length );
|
||||
BOOST_CHECK_EQUAL( size( my_string ), std::char_traits<char>::length( my_string ) );
|
||||
BOOST_CHECK_EQUAL( str_begin( my_string ), my_string );
|
||||
range_iterator<char_array_t>::type str_end2 = str_begin( my_string ) + str_size(my_string);
|
||||
range_iterator<char_array_t>::type str_end3 = str_end(my_string);
|
||||
BOOST_CHECK_EQUAL( str_end3, str_end2 );
|
||||
BOOST_CHECK_EQUAL( str_empty( my_string ), (my_string == 0 || my_string[0] == char()) );
|
||||
BOOST_CHECK_EQUAL( str_size( my_string ), my_string_length );
|
||||
BOOST_CHECK_EQUAL( str_size( my_string ), std::char_traits<char>::length( my_string ) );
|
||||
|
||||
char to_search = 'n';
|
||||
BOOST_CHECK( find_mutable( char_s, to_search ) != end( char_s ) );
|
||||
BOOST_CHECK( find_const( char_s, to_search ) != end( char_s ) );
|
||||
BOOST_CHECK( find_mutable( char_s, to_search ) != str_end( char_s ) );
|
||||
BOOST_CHECK( find_const( char_s, to_search ) != str_end(char_s) );
|
||||
|
||||
BOOST_CHECK( find_mutable( my_string, to_search ) != end( my_string ) );
|
||||
BOOST_CHECK( find_const( my_string, to_search ) != end( my_string ) );
|
||||
BOOST_CHECK( find_mutable( my_string, to_search ) != str_end(my_string) );
|
||||
BOOST_CHECK( find_const( my_string, to_search ) != str_end(my_string) );
|
||||
|
||||
BOOST_CHECK( find_mutable( char_s2, to_search ) != end( char_s2 ) );
|
||||
BOOST_CHECK( find_const( char_s2, to_search ) != end( char_s2 ) );
|
||||
BOOST_CHECK( find_mutable( char_s2, to_search ) != str_end(char_s) );
|
||||
BOOST_CHECK( find_const( char_s2, to_search ) != str_end(char_s2) );
|
||||
|
||||
BOOST_CHECK( find_const( as_array( my_string ), to_search ) != str_end(my_string) );
|
||||
BOOST_CHECK( find_const( as_array( my_const_string ), to_search ) != str_end(my_string) );
|
||||
}
|
||||
|
||||
|
||||
@ -148,31 +185,31 @@ void check_string()
|
||||
BOOST_STATIC_ASSERT(( is_same< range_value<wchar_iterator_t>::type,
|
||||
detail::iterator_traits<wchar_iterator_t>::value_type>::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< range_iterator<wchar_iterator_t>::type, wchar_iterator_t >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< range_const_iterator<wchar_iterator_t>::type, const wchar_t* >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< range_iterator<const wchar_t*>::type, const wchar_t* >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< range_difference<wchar_iterator_t>::type,
|
||||
detail::iterator_traits<wchar_iterator_t>::difference_type >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< range_size<wchar_iterator_t>::type, std::size_t >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< range_result_iterator<wchar_iterator_t>::type, wchar_iterator_t >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< range_result_iterator<const wchar_t*>::type, const wchar_t* >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< range_iterator<wchar_iterator_t>::type, wchar_iterator_t >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< range_iterator<const wchar_t*>::type, const wchar_t* >::value ));
|
||||
|
||||
std::size_t sz = size( char_ws );
|
||||
BOOST_CHECK_EQUAL( begin( char_ws ), char_ws );
|
||||
BOOST_CHECK_EQUAL( end( char_ws ), (begin( char_ws ) + sz) );
|
||||
BOOST_CHECK_EQUAL( empty( char_ws ), (char_ws == 0 || char_ws[0] == wchar_t()) );
|
||||
std::size_t sz = str_size( char_ws );
|
||||
BOOST_CHECK_EQUAL( str_begin( char_ws ), char_ws );
|
||||
BOOST_CHECK_EQUAL( str_end(char_ws), (str_begin( char_ws ) + sz) );
|
||||
BOOST_CHECK_EQUAL( str_empty( char_ws ), (char_ws == 0 || char_ws[0] == wchar_t()) );
|
||||
BOOST_CHECK_EQUAL( sz, std::char_traits<wchar_t>::length( char_ws ) );
|
||||
/*
|
||||
std::size_t sz2 = size( char_ws2 );
|
||||
BOOST_CHECK_EQUAL( begin( char_ws2 ), char_ws2 );
|
||||
BOOST_CHECK_EQUAL( end( char_ws2 ), (begin( char_ws2 ) + sz2) );
|
||||
BOOST_CHECK_EQUAL( str_begin( char_ws2 ), char_ws2 );
|
||||
BOOST_CHECK_EQUAL( str_end( char_ws2 ), (begin( char_ws2 ) + sz2) );
|
||||
BOOST_CHECK_EQUAL( empty( char_ws2 ), (char_ws2 == 0 || char_ws2[0] == wchar_t()) );
|
||||
BOOST_CHECK_EQUAL( sz2, std::char_traits<wchar_t>::length( char_ws2 ) );
|
||||
*/
|
||||
wchar_t to_search = L'n';
|
||||
BOOST_CHECK( find( char_ws, to_search ) != end( char_ws ) );
|
||||
BOOST_CHECK( find( char_ws, to_search ) != str_end(char_ws) );
|
||||
|
||||
#if BOOST_WORKAROUND(_MSC_VER, BOOST_TESTED_AT(1300))
|
||||
|
||||
BOOST_CHECK( find( my_wstring, to_search ) != end( my_wstring ) );
|
||||
BOOST_CHECK( find( my_wstring, to_search ) != str_end(my_wstring) );
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@ -181,7 +218,6 @@ void check_string()
|
||||
|
||||
}
|
||||
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
using boost::unit_test::test_suite;
|
||||
|
||||
|
Reference in New Issue
Block a user