forked from boostorg/range
*** empty log message ***
[SVN r23241]
This commit is contained in:
59
test/Jamfile
Executable file
59
test/Jamfile
Executable file
@ -0,0 +1,59 @@
|
||||
subproject libs/range/test ;
|
||||
|
||||
SEARCH on testing.jam = $(BOOST_BUILD_PATH) ;
|
||||
include testing.jam ;
|
||||
DEPENDS all : test ;
|
||||
|
||||
{
|
||||
test-suite range
|
||||
: [ run
|
||||
array.cpp
|
||||
: :
|
||||
:
|
||||
: array_test
|
||||
]
|
||||
[ run
|
||||
iterator_pair.cpp
|
||||
: :
|
||||
:
|
||||
: iterator_pair_test
|
||||
]
|
||||
[ run
|
||||
std_container.cpp
|
||||
: :
|
||||
:
|
||||
: std_container_test
|
||||
]
|
||||
[ run
|
||||
string.cpp
|
||||
: :
|
||||
:
|
||||
: string_test
|
||||
]
|
||||
[ run
|
||||
iterator_range.cpp
|
||||
: :
|
||||
:
|
||||
: iterator_range
|
||||
]
|
||||
|
||||
[ run
|
||||
partial_workaround.cpp
|
||||
: :
|
||||
:
|
||||
: workaround_test
|
||||
]
|
||||
[ run
|
||||
algorithm_example.cpp
|
||||
: :
|
||||
:
|
||||
: example_test
|
||||
]
|
||||
|
||||
[ run
|
||||
reversible_range.cpp
|
||||
: :
|
||||
:
|
||||
: reversible_range_test
|
||||
] ;
|
||||
}
|
86
test/TODO
Normal file
86
test/TODO
Normal file
@ -0,0 +1,86 @@
|
||||
1. ok. I should add something about extending the lib + how to rely on ADL.
|
||||
2. | I'd prefer "primary specialization" to "default" in the comments.
|
||||
ok. Is that the correct term?
|
||||
3. A "specialization" of a template is the result of instantiating
|
||||
it, so the more accurate term, as given in Vandevoorde and
|
||||
Josuttis, is "primary template."
|
||||
|
||||
5. new intro:
|
||||
"When writing generic code that works with Standard Library
|
||||
containers, one often finds it desirable to extend that code to
|
||||
work with other types that offer enough functionality to satisfy
|
||||
the needs of the generic code, but in an altered form. For
|
||||
example, raw arrays are often suitable for use with generic code
|
||||
that works with containers, provided a suitable adapter is used.
|
||||
Likewise, null terminated strings can be treated as containers of
|
||||
characters, if suitably adapted. This library provides the means
|
||||
to adapt Standard Library containers, null terminated strings,
|
||||
std::pairs of iterators, and raw arrays, such that the same
|
||||
generic code can work with them all."
|
||||
|
||||
6. > | The Introduction is missing discussion of the use of namespace
|
||||
> | scope functions to do what heretofore would be done via member
|
||||
> | functions. Instead, the example and the sentence immediately
|
||||
> | following it imply this change of syntax.
|
||||
>
|
||||
> Wouldn't it only duplicate stuff in the two links to CollectionCocept and ExternalConcepts?
|
||||
|
||||
In a sense, yes, but what I'm proposing is a much abbreviated
|
||||
form:
|
||||
|
||||
"To allow generic code to work with objects that conform to the
|
||||
ExternalCollectionConcept, this library provides a set of
|
||||
namespace scope functions and <A
|
||||
href="http://www.boost.org/more/generic_programming.html#type_generator">type
|
||||
generators</A> that provide a standard interface for the required
|
||||
functionality. Whereas one might write, "c.end()," to get the end
|
||||
iterator from a Standard Library container, c, using this
|
||||
library, it would be written, "boost::end(c)." This change in
|
||||
syntax is necessary to make the same interface possible with the
|
||||
other supported types such as null terminated strings."
|
||||
|
||||
7. [boost-book-style]I like colors, so perhaps use the boost-book stylesheets?
|
||||
|
||||
9. New range explanation:
|
||||
|
||||
I'd say "Iterable" if we have to use an "-able" term. 24.1/7
|
||||
suggests to me that "Range" might be OK:
|
||||
|
||||
Most of the library's algorithmic templates that operate on data
|
||||
structures have interfaces that use ranges. A range is a pair of
|
||||
iterators that designate the beginning and end of the computation. A
|
||||
range [i, i) is an empty range; in general, a range [i, j) refers to
|
||||
the elements in the data structure starting with the one pointed to
|
||||
by i and up to but not including the one pointed to by j. Range [i,
|
||||
j) is valid if and only if j is reachable from i. The result of the
|
||||
application of functions in the library to invalid ranges is
|
||||
undefined.
|
||||
|
||||
10. Don't make empty part of the Range concept, but have a default
|
||||
implementation begin() == end() + spccial treatment of char*,
|
||||
|
||||
11. documentation: table with entities before other tables
|
||||
|
||||
12. Example of how result_iterator is used, necessary:
|
||||
when designing templated classes
|
||||
|
||||
template<class container> struct widget {
|
||||
typedef result_iterator_of<container> iterator;
|
||||
};
|
||||
|
||||
13. better external concepts: Thorsten Ottosen wrote:
|
||||
>> The documentation that's provided I found
|
||||
>> sufficient, it's just of a different style than other concept
|
||||
>> documentation.
|
||||
>
|
||||
> ok. I don't think the definition of concepts are that much more
|
||||
> elaborate. What could be
|
||||
> much better is the example which could follow normal concept
|
||||
> standards. Is that what you had in mind?
|
||||
|
||||
Yes.
|
||||
|
||||
14. Change example code for my_generic_replace.
|
||||
|
||||
15. More concepts: random-access range: which have constant
|
||||
time size(); Cpm matthews latest article.
|
65
test/algorithm_example.cpp
Executable file
65
test/algorithm_example.cpp
Executable file
@ -0,0 +1,65 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Thorsten Ottosen 2003-2004. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
|
||||
#include <boost/range.hpp>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
namespace
|
||||
{
|
||||
template< typename ExternalCollection, typename T >
|
||||
inline typename boost::iterator_of<ExternalCollection>::type
|
||||
find( ExternalCollection& c, const T& value )
|
||||
{
|
||||
return std::find( boost::begin( c ), boost::end( c ), value );
|
||||
}
|
||||
|
||||
template< typename ExternalCollection, typename T >
|
||||
inline typename boost::const_iterator_of<ExternalCollection>::type
|
||||
find( const ExternalCollection& c, const T& value )
|
||||
{
|
||||
return std::find( boost::begin( c ), boost::end( c ), value );
|
||||
}
|
||||
|
||||
//
|
||||
// replace first value and return its index
|
||||
//
|
||||
template< typename EC, typename T >
|
||||
inline typename boost::size_type_of< EC >::type
|
||||
my_generic_replace( EC& c, const T& value, const T& replacement )
|
||||
{
|
||||
typename boost::iterator_of<EC>::type found = find( c, value );
|
||||
|
||||
if( found != boost::end( c ) )
|
||||
*found = replacement;
|
||||
return std::distance( boost::begin( c ), found );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
const int N = 5;
|
||||
int v[] = { 1,2,3,4,5,6,6,7,8,9 };
|
||||
std::vector<int> my_vector;
|
||||
my_vector.assign( boost::begin( v ), boost::end( v ) );
|
||||
typedef std::vector<int>::iterator iterator;
|
||||
std::pair<iterator,iterator> my_view( boost::begin( my_vector ),
|
||||
boost::begin( my_vector ) + N );
|
||||
char str[] = "a string";
|
||||
|
||||
std::cout << my_generic_replace( my_vector, 4, 2 )
|
||||
<< my_generic_replace( my_view, 4, 2 )
|
||||
<< my_generic_replace( str, 'a', 'b' );
|
||||
return 0;
|
||||
}
|
76
test/array.cpp
Executable file
76
test/array.cpp
Executable file
@ -0,0 +1,76 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Thorsten Ottosen 2003-2004. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
|
||||
#include <boost/range.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/type_traits.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using namespace boost;
|
||||
using namespace std;
|
||||
|
||||
void check_array()
|
||||
{
|
||||
const int sz = 9;
|
||||
typedef int array_t[sz];
|
||||
int my_array[sz] = { 1,2,3,4,5,6,7,8,9 };
|
||||
const array_t ca = { 1,2,3,4,5,6,7,8,10 };
|
||||
|
||||
#ifndef BOOST_CT_NO_STATIC_ASSERT
|
||||
BOOST_STATIC_ASSERT(( is_same< value_type_of<array_t>::type, int >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< iterator_of<array_t>::type, int* >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< const_iterator_of<array_t>::type, const int* >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< difference_type_of<array_t>::type, std::ptrdiff_t >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< size_type_of<array_t>::type, std::size_t >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< result_iterator_of<array_t>::type, int* >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< result_iterator_of<const array_t>::type, const int* >::value ));
|
||||
|
||||
BOOST_STATIC_ASSERT(( is_same< value_type_of<const array_t>::type, const int >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< iterator_of<const array_t>::type, const int* >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< const_iterator_of<const array_t>::type, const int* >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< difference_type_of<const array_t>::type, std::ptrdiff_t >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< size_type_of<const array_t>::type, std::size_t >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< result_iterator_of<const array_t>::type, const int* >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< result_iterator_of<const array_t>::type, const int* >::value ));
|
||||
#endif
|
||||
//typedef container<const array_t>::result_iterator iter;
|
||||
//cout << typeid( iter() ).name() << endl;
|
||||
|
||||
BOOST_CHECK_EQUAL( begin( my_array ), my_array );
|
||||
BOOST_CHECK_EQUAL( end( my_array ), my_array + size( my_array ) );
|
||||
BOOST_CHECK_EQUAL( empty( my_array ), false );
|
||||
//BOOST_CHECK( size( my_array ) == sizeof( sizer( my_array ) ) );
|
||||
|
||||
BOOST_CHECK_EQUAL( begin( ca ), ca );
|
||||
BOOST_CHECK_EQUAL( end( ca ), ca + size( ca ) );
|
||||
BOOST_CHECK_EQUAL( empty( ca ),false );
|
||||
//BOOST_CHECK( size( ca ) == sizeof( sizer( ca ) ) );
|
||||
|
||||
}
|
||||
|
||||
#include <boost/test/included/unit_test_framework.hpp>
|
||||
|
||||
using boost::unit_test_framework::test_suite;
|
||||
|
||||
test_suite* init_unit_test_suite( int argc, char* argv[] )
|
||||
{
|
||||
test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &check_array ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
92
test/iterator_pair.cpp
Executable file
92
test/iterator_pair.cpp
Executable file
@ -0,0 +1,92 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Thorsten Ottosen 2003-2004. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
|
||||
#include <boost/range.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/type_traits.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <vector>
|
||||
|
||||
using namespace boost;
|
||||
using boost::unit_test_framework::test_suite;
|
||||
|
||||
void check_iterator_pair()
|
||||
{
|
||||
typedef std::vector<int> vec_t;
|
||||
vec_t vec;
|
||||
vec.push_back( 4 );
|
||||
typedef std::pair<vec_t::iterator,vec_t::iterator>
|
||||
pair_t;
|
||||
typedef std::pair<vec_t::const_iterator,vec_t::const_iterator>
|
||||
const_pair_t;
|
||||
typedef const pair_t const_pair_tt;
|
||||
pair_t pair = std::make_pair( begin( vec ), end( vec ) );
|
||||
const_pair_t const_pair = std::make_pair( begin( vec ), end( vec ) );
|
||||
const_pair_tt constness_pair( pair );
|
||||
|
||||
|
||||
BOOST_STATIC_ASSERT(( is_same< value_type_of<pair_t>::type,
|
||||
detail::iterator_traits<pair_t::first_type>::value_type>::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< iterator_of<pair_t>::type, pair_t::first_type >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< const_iterator_of<pair_t>::type, pair_t::first_type >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< difference_type_of<pair_t>::type,
|
||||
detail::iterator_traits<pair_t::first_type>::difference_type >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< size_type_of<pair_t>::type, std::size_t >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< result_iterator_of<pair_t>::type, pair_t::first_type >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< result_iterator_of<const_pair_t>::type, const_pair_t::first_type >::value ));
|
||||
|
||||
BOOST_STATIC_ASSERT(( is_same< value_type_of<const_pair_tt>::type,
|
||||
detail::iterator_traits<const_pair_t::first_type>::value_type>::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< iterator_of<const_pair_tt>::type, const_pair_tt::first_type >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< const_iterator_of<const_pair_tt>::type, const_pair_tt::first_type >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< difference_type_of<const_pair_tt>::type,
|
||||
detail::iterator_traits<const_pair_tt::first_type>::difference_type >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< size_type_of<const_pair_tt>::type, std::size_t >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< result_iterator_of<const_pair_tt>::type, const_pair_tt::first_type >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< result_iterator_of<const_pair_tt>::type, const_pair_tt::first_type >::value ));
|
||||
|
||||
BOOST_CHECK( begin( pair ) == pair.first );
|
||||
BOOST_CHECK( end( pair ) == pair.second );
|
||||
BOOST_CHECK( empty( pair ) == (pair.first == pair.second) );
|
||||
BOOST_CHECK( size( pair ) == std::size_t( std::distance( pair.first, pair.second ) ) );
|
||||
|
||||
BOOST_CHECK( begin( const_pair ) == const_pair.first );
|
||||
BOOST_CHECK( end( const_pair ) == const_pair.second );
|
||||
BOOST_CHECK( empty( const_pair ) == (const_pair.first == const_pair.second) );
|
||||
BOOST_CHECK( size( const_pair ) == std::size_t( std::distance( const_pair.first, const_pair.second ) ) );
|
||||
|
||||
BOOST_CHECK( begin( constness_pair ) == constness_pair.first );
|
||||
BOOST_CHECK( end( constness_pair ) == constness_pair.second );
|
||||
BOOST_CHECK( empty( constness_pair ) == (constness_pair.first == const_pair.second) );
|
||||
BOOST_CHECK( size( constness_pair ) == std::size_t( std::distance( constness_pair.first, constness_pair.second ) ) );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include <boost/test/included/unit_test_framework.hpp>
|
||||
|
||||
using boost::unit_test_framework::test_suite;
|
||||
|
||||
test_suite* init_unit_test_suite( int argc, char* argv[] )
|
||||
{
|
||||
test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &check_iterator_pair ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
95
test/iterator_range.cpp
Executable file
95
test/iterator_range.cpp
Executable file
@ -0,0 +1,95 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Thorsten Ottosen 2003-2004. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
|
||||
#include <boost/range/iterator_range.hpp>
|
||||
#include <boost/range/sub_range.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace boost;
|
||||
using namespace std;
|
||||
|
||||
struct add_one
|
||||
{
|
||||
template< class T >
|
||||
T operator()( T r ) const
|
||||
{
|
||||
return r + 1;
|
||||
}
|
||||
};
|
||||
|
||||
void check_iterator_range()
|
||||
{
|
||||
typedef string::iterator iterator;
|
||||
typedef string::const_iterator const_iterator;
|
||||
typedef iterator_range<iterator> irange;
|
||||
typedef iterator_range<const_iterator> cirange;
|
||||
string str = "hello world";
|
||||
const string cstr = "const world";
|
||||
irange r = make_iterator_range( str );
|
||||
r = make_iterator_range( str.begin(), str.end() );
|
||||
cirange r2 = make_iterator_range( cstr );
|
||||
r2 = make_iterator_range( cstr.begin(), cstr.end() );
|
||||
r2 = make_iterator_range( str );
|
||||
|
||||
typedef sub_range<string> srange;
|
||||
typedef sub_range<const string> csrange;
|
||||
srange s = r;
|
||||
BOOST_CHECK( r == s );
|
||||
s = make_iterator_range( str );
|
||||
csrange s2 = r;
|
||||
s2 = r2;
|
||||
s2 = make_iterator_range( cstr );
|
||||
BOOST_CHECK( r != s2 );
|
||||
s2 = make_iterator_range( str );
|
||||
|
||||
BOOST_CHECK( r.begin() == s.begin() );
|
||||
BOOST_CHECK( r2.begin()== s2.begin() );
|
||||
BOOST_CHECK( r.end() == s.end() );
|
||||
BOOST_CHECK( r2.end() == s2.end() );
|
||||
BOOST_CHECK_EQUAL( r.size(), s.size() );
|
||||
BOOST_CHECK_EQUAL( r2.size(), s2.size() );
|
||||
|
||||
if( !r )
|
||||
BOOST_CHECK( false );
|
||||
if( !r2 )
|
||||
BOOST_CHECK( false );
|
||||
if( !s )
|
||||
BOOST_CHECK( false );
|
||||
if( !s2 )
|
||||
BOOST_CHECK( false );
|
||||
|
||||
cout << r << r2 << s << s2;
|
||||
|
||||
string res = copy_range<string>( r );
|
||||
BOOST_CHECK( equal( res.begin(), res.end(), r.begin() ) );
|
||||
string res2 = transform_range<string>( s2, add_one() );
|
||||
BOOST_CHECK( !equal( s2.begin(), s2.end(), res2.begin() ) );
|
||||
}
|
||||
|
||||
#include <boost/test/included/unit_test_framework.hpp>
|
||||
|
||||
using boost::unit_test_framework::test_suite;
|
||||
|
||||
test_suite* init_unit_test_suite( int argc, char* argv[] )
|
||||
{
|
||||
test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &check_iterator_range ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
106
test/partial_workaround.cpp
Executable file
106
test/partial_workaround.cpp
Executable file
@ -0,0 +1,106 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Thorsten Ottosen 2003-2004. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
|
||||
#define BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION 1
|
||||
|
||||
#include <boost/range/iterator.hpp>
|
||||
#include <boost/range/const_iterator.hpp>
|
||||
#include <boost/range/size_type.hpp>
|
||||
#include <boost/range/value_type.hpp>
|
||||
#include <boost/range/difference_type.hpp>
|
||||
#include <boost/range/result_iterator.hpp>
|
||||
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/range/size.hpp>
|
||||
#include <boost/range/empty.hpp>
|
||||
#include <boost/range/detail/sfinae.hpp>
|
||||
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/type_traits.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using namespace boost;
|
||||
using namespace std;
|
||||
|
||||
void check_partial_workaround()
|
||||
{
|
||||
using namespace range_detail;
|
||||
using type_traits::yes_type;
|
||||
using type_traits::no_type;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// string
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
char* c_ptr;
|
||||
const char* cc_ptr;
|
||||
wchar_t* w_ptr;
|
||||
const wchar_t* cw_ptr;
|
||||
|
||||
BOOST_STATIC_ASSERT( sizeof( yes_type ) == sizeof( is_string_impl( c_ptr ) ) );
|
||||
BOOST_STATIC_ASSERT( sizeof( yes_type ) == sizeof( is_string_impl( cc_ptr ) ) );
|
||||
BOOST_STATIC_ASSERT( sizeof( yes_type ) == sizeof( is_string_impl( w_ptr ) ) );
|
||||
BOOST_STATIC_ASSERT( sizeof( yes_type ) == sizeof( is_string_impl( cw_ptr ) ) );
|
||||
|
||||
BOOST_STATIC_ASSERT( sizeof( yes_type ) == sizeof( is_char_ptr_impl( c_ptr ) ) );
|
||||
BOOST_STATIC_ASSERT( sizeof( no_type ) == sizeof( is_char_ptr_impl( cc_ptr ) ) );
|
||||
|
||||
BOOST_STATIC_ASSERT( sizeof( yes_type ) == sizeof( is_wchar_t_ptr_impl( w_ptr ) ) );
|
||||
BOOST_STATIC_ASSERT( sizeof( no_type ) == sizeof( is_wchar_t_ptr_impl( cw_ptr ) ) );
|
||||
|
||||
BOOST_STATIC_ASSERT( sizeof( yes_type ) == sizeof( is_const_char_ptr_impl( c_ptr ) ) );
|
||||
BOOST_STATIC_ASSERT( sizeof( yes_type ) == sizeof( is_const_char_ptr_impl( cc_ptr ) ) );
|
||||
|
||||
BOOST_STATIC_ASSERT( sizeof( yes_type ) == sizeof( is_const_wchar_t_ptr_impl( w_ptr ) ) );
|
||||
BOOST_STATIC_ASSERT( sizeof( yes_type ) == sizeof( is_const_wchar_t_ptr_impl( cw_ptr ) ) );
|
||||
|
||||
BOOST_STATIC_ASSERT(( boost::is_same< boost::range_detail::std_container_,
|
||||
boost::range_detail::range< vector<int> >::type >::value ));
|
||||
BOOST_STATIC_ASSERT(( boost::is_same< boost::range_detail::std_pair_,
|
||||
boost::range_detail::range< pair<int,int> >::type >::value ));
|
||||
BOOST_STATIC_ASSERT(( boost::is_same< boost::range_detail::array_,
|
||||
boost::range_detail::range< int[42] >::type >::value ));
|
||||
BOOST_STATIC_ASSERT(( boost::is_same< boost::range_detail::char_ptr_,
|
||||
boost::range_detail::range< char* >::type >::value ));
|
||||
BOOST_STATIC_ASSERT(( boost::is_same< boost::range_detail::const_char_ptr_,
|
||||
boost::range_detail::range< const char* >::type >::value ));
|
||||
BOOST_STATIC_ASSERT(( boost::is_same< boost::range_detail::wchar_t_ptr_,
|
||||
boost::range_detail::range< wchar_t* >::type >::value ));
|
||||
BOOST_STATIC_ASSERT(( boost::is_same< boost::range_detail::const_wchar_t_ptr_,
|
||||
boost::range_detail::range< const wchar_t* >::type >::value ));
|
||||
BOOST_STATIC_ASSERT(( boost::is_same< boost::range_detail::std_container_,
|
||||
boost::range_detail::range< vector<int> >::type >::value ));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#include <boost/test/included/unit_test_framework.hpp>
|
||||
|
||||
using boost::unit_test_framework::test_suite;
|
||||
|
||||
test_suite* init_unit_test_suite( int argc, char* argv[] )
|
||||
{
|
||||
test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &check_partial_workaround ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
97
test/reversible_range.cpp
Executable file
97
test/reversible_range.cpp
Executable file
@ -0,0 +1,97 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Thorsten Ottosen 2003-2004. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
|
||||
|
||||
#include <boost/range/rbegin.hpp>
|
||||
#include <boost/range/rend.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/type_traits.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace boost;
|
||||
using namespace std;
|
||||
|
||||
void check_iterator()
|
||||
{
|
||||
typedef vector<char> vec_t;
|
||||
typedef vec_t::iterator iterator;
|
||||
typedef pair<iterator,iterator> pair_t;
|
||||
typedef reverse_iterator_of<pair_t>::type rev_iterator;
|
||||
typedef pair<rev_iterator,rev_iterator> rev_pair_t;
|
||||
|
||||
vec_t vec;
|
||||
pair_t p = make_pair( vec.begin(), vec.end() );
|
||||
rev_pair_t rp = make_pair( rbegin( p ), rend( p ) );
|
||||
char* str = "mutable";
|
||||
const char* cstr = "not mutable";
|
||||
char a[] = "mutable";
|
||||
const char ca[] = "not mutable";
|
||||
wchar_t* wstr = L"mutable";
|
||||
const wchar_t* cwstr= L"not mutable";
|
||||
wchar_t wa[] = L"mutable";
|
||||
const wchar_t cwa[]= L"not mutable";
|
||||
|
||||
BOOST_CHECK( rbegin( vec ) == reverse_iterator_of<vec_t>::type( vec.end() ) );
|
||||
BOOST_CHECK( rend( vec ) == reverse_iterator_of<vec_t>::type( vec.begin() ) );
|
||||
BOOST_CHECK( distance( rbegin( vec ), rend( vec ) ) == distance( begin( vec ), end( vec ) ) );
|
||||
|
||||
BOOST_CHECK( rbegin( p ) == begin( rp ) );
|
||||
BOOST_CHECK( rend( p ) == end( rp ) );
|
||||
BOOST_CHECK( distance( rbegin( p ), rend( p ) ) == distance( begin( rp ), end( rp ) ) );
|
||||
BOOST_CHECK( distance( begin( p ), end( p ) ) == distance( rbegin( rp ), rend( rp ) ) );
|
||||
|
||||
BOOST_CHECK_EQUAL( &*begin( str ), &*( rend( str ) - 1 ) );
|
||||
BOOST_CHECK_EQUAL( &*( end( str ) - 1 ), &*rbegin( str ) );
|
||||
BOOST_CHECK_EQUAL( &*begin( cstr ), &*( rend( cstr ) - 1 ) );
|
||||
BOOST_CHECK_EQUAL( &*( end( cstr ) - 1 ), &*rbegin( cstr ) );
|
||||
|
||||
BOOST_CHECK_EQUAL( &*begin( a ), &*( rend( a ) - 1 ) );
|
||||
BOOST_CHECK_EQUAL( &*( end( a ) - 1 ), &*rbegin( a ) );
|
||||
BOOST_CHECK_EQUAL( &*begin( ca ), &*( rend( ca ) - 1 ) );
|
||||
BOOST_CHECK_EQUAL( &*( end( ca ) - 1 ), &*rbegin( ca ) );
|
||||
|
||||
BOOST_CHECK_EQUAL( &*begin( wstr ), &*( rend( wstr ) - 1 ) );
|
||||
BOOST_CHECK_EQUAL( &*( end( wstr ) - 1 ), &*rbegin( wstr ) );
|
||||
BOOST_CHECK_EQUAL( &*begin( cwstr ), &*( rend( cwstr ) - 1 ) );
|
||||
BOOST_CHECK_EQUAL( &*( end( cwstr ) - 1 ), &*rbegin( cwstr ) );
|
||||
|
||||
BOOST_CHECK_EQUAL( &*begin( wa ), &*( rend( wa ) - 1 ) );
|
||||
BOOST_CHECK_EQUAL( &*( end( wa ) - 1 ), &*rbegin( wa ) );
|
||||
BOOST_CHECK_EQUAL( &*begin( cwa ), &*( rend( cwa ) - 1 ) );
|
||||
BOOST_CHECK_EQUAL( &*( end( cwa ) - 1 ), &*rbegin( cwa ) );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include <boost/test/included/unit_test_framework.hpp>
|
||||
|
||||
using boost::unit_test_framework::test_suite;
|
||||
|
||||
test_suite* init_unit_test_suite( int argc, char* argv[] )
|
||||
{
|
||||
test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &check_iterator ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
74
test/std_container.cpp
Executable file
74
test/std_container.cpp
Executable file
@ -0,0 +1,74 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Thorsten Ottosen 2003-2004. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
|
||||
#include <boost/range.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/type_traits.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <vector>
|
||||
|
||||
using namespace boost;
|
||||
using boost::unit_test_framework::test_suite;
|
||||
|
||||
void check_std_container()
|
||||
{
|
||||
typedef std::vector<int> vec_t;
|
||||
vec_t vec;
|
||||
vec.push_back( 3 ); vec.push_back( 4 );
|
||||
const vec_t cvec( vec );
|
||||
|
||||
BOOST_STATIC_ASSERT(( is_same< value_type_of<vec_t>::type, vec_t::value_type >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< iterator_of<vec_t>::type, vec_t::iterator >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< const_iterator_of<vec_t>::type, vec_t::const_iterator >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< difference_type_of<vec_t>::type, vec_t::difference_type >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< size_type_of<vec_t>::type, vec_t::size_type >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< result_iterator_of<vec_t>::type, vec_t::iterator >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< result_iterator_of<const vec_t>::type, vec_t::const_iterator >::value ));
|
||||
|
||||
BOOST_STATIC_ASSERT(( is_same< value_type_of<const vec_t>::type, vec_t::value_type >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< iterator_of<const vec_t>::type, vec_t::iterator >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< const_iterator_of<const vec_t>::type, vec_t::const_iterator >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< difference_type_of<const vec_t>::type, vec_t::difference_type >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< size_type_of<const vec_t>::type, vec_t::size_type >::value ));
|
||||
|
||||
BOOST_CHECK( begin( vec ) == vec.begin() );
|
||||
BOOST_CHECK( end( vec ) == vec.end() );
|
||||
BOOST_CHECK( empty( vec ) == vec.empty() );
|
||||
BOOST_CHECK( size( vec ) == vec.size() );
|
||||
|
||||
BOOST_CHECK( begin( cvec ) == cvec.begin() );
|
||||
BOOST_CHECK( end( cvec ) == cvec.end() );
|
||||
BOOST_CHECK( empty( cvec ) == cvec.empty() );
|
||||
BOOST_CHECK( size( cvec ) == cvec.size() );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#include <boost/test/included/unit_test_framework.hpp>
|
||||
|
||||
using boost::unit_test_framework::test_suite;
|
||||
|
||||
test_suite* init_unit_test_suite( int argc, char* argv[] )
|
||||
{
|
||||
test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &check_std_container ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
152
test/string.cpp
Executable file
152
test/string.cpp
Executable file
@ -0,0 +1,152 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Thorsten Ottosen 2003-2004. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
|
||||
#include <boost/range.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/type_traits.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
|
||||
template< typename Container, typename T >
|
||||
BOOST_DEDUCED_TYPENAME boost::iterator_of<Container>::type
|
||||
find( Container& c, T value )
|
||||
{
|
||||
return std::find( boost::begin( c ), boost::end( c ), value );
|
||||
}
|
||||
|
||||
template< typename Container, typename T >
|
||||
BOOST_DEDUCED_TYPENAME boost::const_iterator_of<Container>::type
|
||||
find( const Container& c, T value )
|
||||
{
|
||||
return std::find( boost::begin( c ), boost::end( c ), value );
|
||||
}
|
||||
|
||||
std::vector<char>
|
||||
check_rvalue_return()
|
||||
{
|
||||
return std::vector<char>( 10, 'm' );
|
||||
}
|
||||
|
||||
using namespace boost;
|
||||
|
||||
|
||||
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 int my_string_length = 14;
|
||||
|
||||
|
||||
BOOST_STATIC_ASSERT(( is_same< value_type_of<char_iterator_t>::type,
|
||||
detail::iterator_traits<char_iterator_t>::value_type>::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< iterator_of<char_iterator_t>::type, char_iterator_t >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< const_iterator_of<char_iterator_t>::type, const char* >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< difference_type_of<char_iterator_t>::type,
|
||||
::std::ptrdiff_t >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< size_type_of<char_iterator_t>::type, std::size_t >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< result_iterator_of<char_iterator_t>::type, char_iterator_t >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< result_iterator_of<const char*>::type, const char* >::value ));
|
||||
//
|
||||
// note: why does is_same< result_iterator<const char_iterator_t>::type, const char* >::value
|
||||
// fail?!?
|
||||
|
||||
BOOST_STATIC_ASSERT(( is_same< value_type_of<char_array_t>::type,
|
||||
char>::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< iterator_of<char_array_t>::type, char* >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< const_iterator_of<char_array_t>::type, const char* >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< difference_type_of<char_array_t>::type,
|
||||
::std::ptrdiff_t >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< size_type_of<char_array_t>::type, std::size_t >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< result_iterator_of<char_array_t>::type, char* >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< result_iterator_of<const char_array_t>::type, const char* >::value ));
|
||||
|
||||
BOOST_CHECK_EQUAL( begin( char_s ), char_s );
|
||||
const char* end1 = begin( char_s ) + size( char_s );
|
||||
BOOST_CHECK_EQUAL( end( char_s ), end1 );
|
||||
BOOST_CHECK_EQUAL( empty( char_s ), (char_s == 0 || char_s[0] == char()) );
|
||||
BOOST_CHECK_EQUAL( size( char_s ), std::char_traits<char>::length( char_s ) );
|
||||
|
||||
BOOST_CHECK_EQUAL( begin( my_string ), my_string );
|
||||
const char* end2 = begin( my_string ) + size( my_string );
|
||||
BOOST_CHECK_EQUAL( end( my_string ), 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 ) );
|
||||
|
||||
|
||||
char to_search = 'n';
|
||||
BOOST_CHECK( find( char_s, to_search ) != end( char_s ) );
|
||||
BOOST_CHECK( find( my_string, to_search ) != end( my_string ) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
void check_string()
|
||||
{
|
||||
check_char();
|
||||
// check_char<volatile char>();
|
||||
// check_char<const char>();
|
||||
// check_char<const volatile char>();
|
||||
|
||||
#ifndef BOOST_NO_STD_WSTRING
|
||||
typedef wchar_t* wchar_iterator_t;
|
||||
const wchar_t* char_ws = L"a wide string";
|
||||
wchar_t my_wstring[] = L"another wide string";
|
||||
|
||||
BOOST_STATIC_ASSERT(( is_same< value_type_of<wchar_iterator_t>::type,
|
||||
detail::iterator_traits<wchar_iterator_t>::value_type>::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< iterator_of<wchar_iterator_t>::type, wchar_iterator_t >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< const_iterator_of<wchar_iterator_t>::type, const wchar_t* >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< difference_type_of<wchar_iterator_t>::type,
|
||||
detail::iterator_traits<wchar_iterator_t>::difference_type >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< size_type_of<wchar_iterator_t>::type, std::size_t >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< result_iterator_of<wchar_iterator_t>::type, wchar_iterator_t >::value ));
|
||||
BOOST_STATIC_ASSERT(( is_same< result_iterator_of<const wchar_t*>::type, const wchar_t* >::value ));
|
||||
|
||||
BOOST_CHECK_EQUAL( begin( char_ws ), char_ws );
|
||||
BOOST_CHECK_EQUAL( end( char_ws ), (begin( char_ws ) + size( char_ws )) );
|
||||
BOOST_CHECK_EQUAL( empty( char_ws ), (char_ws == 0 || char_ws[0] == wchar_t()) );
|
||||
BOOST_CHECK_EQUAL( size( char_ws ), std::char_traits<wchar_t>::length( char_ws ) );
|
||||
|
||||
wchar_t to_search = L'n';
|
||||
BOOST_CHECK( find( char_ws, to_search ) != end( char_ws ) );
|
||||
BOOST_CHECK( find( my_wstring, to_search ) != end( my_wstring ) );
|
||||
#endif
|
||||
|
||||
find( check_rvalue_return(), 'n' );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include <boost/test/included/unit_test_framework.hpp>
|
||||
|
||||
using boost::unit_test_framework::test_suite;
|
||||
|
||||
test_suite* init_unit_test_suite( int argc, char* argv[] )
|
||||
{
|
||||
test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &check_string ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user