*** empty log message ***

[SVN r24124]
This commit is contained in:
Thorsten Jørgen Ottosen
2004-07-27 18:28:10 +00:00
parent d73fb64736
commit deb05d7f62
5 changed files with 112 additions and 58 deletions

View File

@ -12,6 +12,7 @@
#define BOOST_RANGE_DETAIL_CONST_ITERATOR_HPP #define BOOST_RANGE_DETAIL_CONST_ITERATOR_HPP
#include <boost/range/detail/common.hpp> #include <boost/range/detail/common.hpp>
#include <boost/type_traits/remove_bounds.hpp>
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// missing partial specialization workaround. // missing partial specialization workaround.
@ -51,7 +52,8 @@ namespace boost
template< typename T > template< typename T >
struct pts struct pts
{ {
typedef void /*dummy*/ type; typedef const BOOST_RANGE_DEDUCED_TYPENAME
remove_bounds<T>::type* type;
}; };
}; };
@ -61,7 +63,8 @@ namespace boost
template< typename T > template< typename T >
struct pts struct pts
{ {
typedef void /*dummy*/ type; typedef const BOOST_RANGE_DEDUCED_TYPENAME
remove_bounds<T>::type* type;
}; };
}; };

View File

@ -12,6 +12,7 @@
#define BOOST_RANGE_DETAIL_ITERATOR_HPP #define BOOST_RANGE_DETAIL_ITERATOR_HPP
#include <boost/range/detail/common.hpp> #include <boost/range/detail/common.hpp>
#include <boost/type_traits/remove_bounds.hpp>
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// missing partial specialization workaround. // missing partial specialization workaround.
@ -50,7 +51,8 @@ namespace boost
template< typename T > template< typename T >
struct pts struct pts
{ {
typedef void /*dummy*/ type; typedef BOOST_RANGE_DEDUCED_TYPENAME
remove_bounds<T>::type* type;
}; };
}; };
@ -60,7 +62,8 @@ namespace boost
template< typename T > template< typename T >
struct pts struct pts
{ {
typedef void /*dummy*/ type; typedef BOOST_RANGE_DEDUCED_TYPENAME
remove_bounds<T>::type* type;
}; };
}; };

View File

@ -15,7 +15,6 @@
#include <boost/range/begin.hpp> #include <boost/range/begin.hpp>
#include <boost/range/end.hpp> #include <boost/range/end.hpp>
#include <boost/iterator/iterator_traits.hpp> #include <boost/iterator/iterator_traits.hpp>
#include <boost/tuple/tuple.hpp>
#include <iterator> #include <iterator>
#include <algorithm> #include <algorithm>
#include <ostream> #include <ostream>

View File

@ -14,11 +14,8 @@
#include <boost/range/config.hpp> #include <boost/range/config.hpp>
#include <boost/range/iterator_range.hpp> #include <boost/range/iterator_range.hpp>
#include <boost/range/result_iterator.hpp> #include <boost/range/result_iterator.hpp>
#include <boost/range/reverse_result_iterator.hpp>
#include <boost/range/size_type.hpp> #include <boost/range/size_type.hpp>
#include <boost/range/difference_type.hpp> #include <boost/range/difference_type.hpp>
//#include <boost/range/rbegin.hpp>
//#include <boost/range/rend.hpp>
namespace boost namespace boost
{ {
@ -26,6 +23,7 @@ namespace boost
template< class Range > template< class Range >
class sub_range : public iterator_range< BOOST_DEDUCED_TYPENAME result_iterator_of<Range>::type > class sub_range : public iterator_range< BOOST_DEDUCED_TYPENAME result_iterator_of<Range>::type >
{ {
typedef BOOST_DEDUCED_TYPENAME result_iterator_of<Range>::type iterator_t; typedef BOOST_DEDUCED_TYPENAME result_iterator_of<Range>::type iterator_t;
typedef iterator_range< iterator_t > base; typedef iterator_range< iterator_t > base;
@ -66,61 +64,12 @@ namespace boost
size_type size() const size_type size() const
{ {
//
// performance discontinuity problem!!
//
return base::size(); return base::size();
} }
}; };
/*
template< class Range >
class reverse_sub_range : public iterator_range< BOOST_DEDUCED_TYPENAME reverse_result_iterator_of<Range>::type >
{
typedef BOOST_DEDUCED_TYPENAME reverse_result_iterator_of<Range>::type
iterator_t;
typedef iterator_range<iterator_t> base;
public:
using base::iterator;
using base::const_iterator;
using base::value_type;
using base::difference_type;
using base::size_type;
public:
template< class Range2 >
reverse_sub_range( Range2& r ) : base( rbegin( r ), rend( r ) )
{ }
template< class Range2 >
reverse_sub_range( const Range2& r ) : base( rbegin( r ), rend( r ) )
{ }
template< class Iter >
reverse_sub_range( Iter first, Iter last ) :
base( iterator_t( last ), iterator_t( first ) )
{ }
template< class Range2 >
sub_range& operator=( Range2& r )
{
base::operator=( r );
return *this;
}
template< class Range2 >
sub_range& operator=( const Range2& r )
{
base::operator=( r );
return *this;
}
};
*/
} // namespace 'boost' } // namespace 'boost'
#endif #endif

100
test/sub_range.cpp Executable file
View File

@ -0,0 +1,100 @@
// 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>
// This should be included before "using namespace boost",
// otherwise gcc headers will be confused with boost::iterator
// namespace.
#include <boost/test/included/unit_test_framework.hpp>
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() ) );
}
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;
}