mirror of
https://github.com/boostorg/range.git
synced 2025-07-29 04:17:39 +02:00
More cleanups
[SVN r31860]
This commit is contained in:
204
doc/example.cpp
204
doc/example.cpp
@ -3,106 +3,106 @@
|
||||
|
||||
namespace Foo
|
||||
{
|
||||
//
|
||||
// Our sample UDT. A 'Pair'
|
||||
// will work as a range when the stored
|
||||
// elements are iterators.
|
||||
//
|
||||
template< class T >
|
||||
struct Pair
|
||||
{
|
||||
T first, last;
|
||||
};
|
||||
//
|
||||
// Our sample UDT. A 'Pair'
|
||||
// will work as a range when the stored
|
||||
// elements are iterators.
|
||||
//
|
||||
template< class T >
|
||||
struct Pair
|
||||
{
|
||||
T first, last;
|
||||
};
|
||||
|
||||
} // namespace 'Foo'
|
||||
|
||||
namespace boost
|
||||
{
|
||||
//
|
||||
// Specialize metafunctions. We must include the range.hpp header.
|
||||
// We must open the 'boost' namespace.
|
||||
//
|
||||
/*
|
||||
template< class T >
|
||||
struct range_value< Foo::Pair<T> >
|
||||
{
|
||||
typedef typename std::iterator_traits<T>::value_type type;
|
||||
};
|
||||
*/
|
||||
//
|
||||
// Specialize metafunctions. We must include the range.hpp header.
|
||||
// We must open the 'boost' namespace.
|
||||
//
|
||||
/*
|
||||
template< class T >
|
||||
struct range_value< Foo::Pair<T> >
|
||||
{
|
||||
typedef typename std::iterator_traits<T>::value_type type;
|
||||
};
|
||||
*/
|
||||
|
||||
template< class T >
|
||||
struct range_iterator< Foo::Pair<T> >
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
template< class T >
|
||||
struct range_iterator< Foo::Pair<T> >
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template< class T >
|
||||
struct range_const_iterator< Foo::Pair<T> >
|
||||
{
|
||||
//
|
||||
// Remark: this is defined similar to 'range_iterator'
|
||||
// because the 'Pair' type does not distinguish
|
||||
// between an iterator and a const_iterator.
|
||||
//
|
||||
typedef T type;
|
||||
};
|
||||
template< class T >
|
||||
struct range_const_iterator< Foo::Pair<T> >
|
||||
{
|
||||
//
|
||||
// Remark: this is defined similar to 'range_iterator'
|
||||
// because the 'Pair' type does not distinguish
|
||||
// between an iterator and a const_iterator.
|
||||
//
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
/*
|
||||
/*
|
||||
template< class T >
|
||||
struct range_difference< Foo::Pair<T> >
|
||||
{
|
||||
typedef typename std::iterator_traits<T>::difference_type type;
|
||||
};
|
||||
*/
|
||||
struct range_difference< Foo::Pair<T> >
|
||||
{
|
||||
typedef typename std::iterator_traits<T>::difference_type type;
|
||||
};
|
||||
*/
|
||||
|
||||
template< class T >
|
||||
template< class T >
|
||||
struct range_size< Foo::Pair<T> >
|
||||
{
|
||||
int static_assertion[ sizeof( std::size_t ) >=
|
||||
sizeof( typename range_difference< Foo::Pair<T> >::type ) ];
|
||||
typedef std::size_t type;
|
||||
};
|
||||
{
|
||||
int static_assertion[ sizeof( std::size_t ) >=
|
||||
sizeof( typename range_difference< Foo::Pair<T> >::type ) ];
|
||||
typedef std::size_t type;
|
||||
};
|
||||
|
||||
} // namespace 'boost'
|
||||
|
||||
namespace Foo
|
||||
{
|
||||
//
|
||||
// The required functions. These should be defined in
|
||||
// the same namespace as 'Pair', in this case
|
||||
// in namespace 'Foo'.
|
||||
//
|
||||
|
||||
template< class T >
|
||||
inline T boost_range_begin( Pair<T>& x )
|
||||
{
|
||||
return x.first;
|
||||
}
|
||||
//
|
||||
// The required functions. These should be defined in
|
||||
// the same namespace as 'Pair', in this case
|
||||
// in namespace 'Foo'.
|
||||
//
|
||||
|
||||
template< class T >
|
||||
inline T boost_range_begin( Pair<T>& x )
|
||||
{
|
||||
return x.first;
|
||||
}
|
||||
|
||||
template< class T >
|
||||
inline T boost_range_begin( const Pair<T>& x )
|
||||
{
|
||||
return x.first;
|
||||
}
|
||||
inline T boost_range_begin( const Pair<T>& x )
|
||||
{
|
||||
return x.first;
|
||||
}
|
||||
|
||||
template< class T >
|
||||
template< class T >
|
||||
inline T boost_range_end( Pair<T>& x )
|
||||
{
|
||||
return x.last;
|
||||
}
|
||||
{
|
||||
return x.last;
|
||||
}
|
||||
|
||||
template< class T >
|
||||
template< class T >
|
||||
inline T boost_range_end( const Pair<T>& x )
|
||||
{
|
||||
return x.last;
|
||||
}
|
||||
{
|
||||
return x.last;
|
||||
}
|
||||
|
||||
template< class T >
|
||||
inline typename boost::range_size< Pair<T> >::type
|
||||
boost_range_size( const Pair<T>& x )
|
||||
{
|
||||
return std::distance(x.first,x.last);
|
||||
}
|
||||
template< class T >
|
||||
inline typename boost::range_size< Pair<T> >::type
|
||||
boost_range_size( const Pair<T>& x )
|
||||
{
|
||||
return std::distance(x.first,x.last);
|
||||
}
|
||||
|
||||
} // namespace 'Foo'
|
||||
|
||||
@ -110,32 +110,32 @@ namespace Foo
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::vector<int>::iterator iter;
|
||||
std::vector<int> vec;
|
||||
vec.push_back( 42 );
|
||||
Foo::Pair<iter> pair = { vec.begin(), vec.end() };
|
||||
const Foo::Pair<iter>& cpair = pair;
|
||||
//
|
||||
// Notice that we call 'begin' etc with qualification.
|
||||
//
|
||||
iter i = boost::begin( pair );
|
||||
iter e = boost::end( pair );
|
||||
i = boost::begin( cpair );
|
||||
e = boost::end( cpair );
|
||||
boost::range_size< Foo::Pair<iter> >::type s = boost::size( pair );
|
||||
s = boost::size( cpair );
|
||||
boost::range_const_reverse_iterator< Foo::Pair<iter> >::type
|
||||
ri = boost::rbegin( cpair ),
|
||||
re = boost::rend( cpair );
|
||||
|
||||
//
|
||||
// Test metafunctions
|
||||
//
|
||||
typedef std::vector<int>::iterator iter;
|
||||
std::vector<int> vec;
|
||||
vec.push_back( 42 );
|
||||
Foo::Pair<iter> pair = { vec.begin(), vec.end() };
|
||||
const Foo::Pair<iter>& cpair = pair;
|
||||
//
|
||||
// Notice that we call 'begin' etc with qualification.
|
||||
//
|
||||
iter i = boost::begin( pair );
|
||||
iter e = boost::end( pair );
|
||||
i = boost::begin( cpair );
|
||||
e = boost::end( cpair );
|
||||
boost::range_size< Foo::Pair<iter> >::type s = boost::size( pair );
|
||||
s = boost::size( cpair );
|
||||
boost::range_const_reverse_iterator< Foo::Pair<iter> >::type
|
||||
ri = boost::rbegin( cpair ),
|
||||
re = boost::rend( cpair );
|
||||
|
||||
boost::range_value< Foo::Pair<iter> >::type
|
||||
v = *boost::begin(pair);
|
||||
//
|
||||
// Test metafunctions
|
||||
//
|
||||
|
||||
boost::range_difference< Foo::Pair<iter> >::type
|
||||
d = boost::end(pair) - boost::begin(pair);
|
||||
boost::range_value< Foo::Pair<iter> >::type
|
||||
v = *boost::begin(pair);
|
||||
|
||||
boost::range_difference< Foo::Pair<iter> >::type
|
||||
d = boost::end(pair) - boost::begin(pair);
|
||||
}
|
||||
|
||||
|
@ -47,8 +47,8 @@ namespace range_detail
|
||||
}
|
||||
|
||||
template< typename C >
|
||||
inline BOOST_DEDUCED_TYPENAME range_iterator<
|
||||
typename remove_const<C>::type >::type
|
||||
inline BOOST_DEDUCED_TYPENAME range_iterator<
|
||||
typename remove_const<C>::type >::type
|
||||
boost_range_begin( C& c )
|
||||
{
|
||||
return c.begin();
|
||||
@ -142,8 +142,8 @@ namespace range_detail
|
||||
|
||||
|
||||
template< class T >
|
||||
inline BOOST_DEDUCED_TYPENAME range_iterator<
|
||||
typename remove_const<T>::type >::type begin( T& r )
|
||||
inline BOOST_DEDUCED_TYPENAME range_iterator<
|
||||
typename remove_const<T>::type >::type begin( T& r )
|
||||
{
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) && \
|
||||
!BOOST_WORKAROUND(__GNUC__, < 3) \
|
||||
|
@ -21,13 +21,13 @@
|
||||
|
||||
namespace boost
|
||||
{
|
||||
template< class T >
|
||||
struct range_difference
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME iterator_difference<
|
||||
BOOST_DEDUCED_TYPENAME range_const_iterator<T>::type >::type
|
||||
type;
|
||||
};
|
||||
template< class T >
|
||||
struct range_difference
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME iterator_difference<
|
||||
BOOST_DEDUCED_TYPENAME range_const_iterator<T>::type >::type
|
||||
type;
|
||||
};
|
||||
}
|
||||
|
||||
//#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
@ -43,13 +43,13 @@ namespace boost
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// default
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
template< typename C >
|
||||
struct range_difference
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME C::difference_type type;
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// pair
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@ -57,14 +57,14 @@ namespace boost
|
||||
template< typename Iterator >
|
||||
struct range_difference< std::pair<Iterator,Iterator> >
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME
|
||||
typedef BOOST_DEDUCED_TYPENAME
|
||||
iterator_difference<Iterator>::type type;
|
||||
};
|
||||
|
||||
|
||||
template< typename Iterator >
|
||||
struct range_difference< const std::pair<Iterator,Iterator> >
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME
|
||||
typedef BOOST_DEDUCED_TYPENAME
|
||||
iterator_difference<Iterator>::type type;
|
||||
};
|
||||
|
||||
|
@ -26,35 +26,35 @@
|
||||
#include <boost/range/iterator.hpp>
|
||||
#include <boost/range/const_iterator.hpp>
|
||||
|
||||
namespace boost
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) && \
|
||||
!BOOST_WORKAROUND(__GNUC__, < 3) \
|
||||
/**/
|
||||
/**/
|
||||
namespace range_detail
|
||||
{
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// primary template
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
template< typename C >
|
||||
inline BOOST_DEDUCED_TYPENAME range_const_iterator<C>::type
|
||||
boost_range_end( const C& c )
|
||||
{
|
||||
return c.end();
|
||||
}
|
||||
|
||||
|
||||
template< typename C >
|
||||
inline BOOST_DEDUCED_TYPENAME range_iterator<
|
||||
typename remove_const<C>::type >::type
|
||||
inline BOOST_DEDUCED_TYPENAME range_iterator<
|
||||
typename remove_const<C>::type >::type
|
||||
boost_range_end( C& c )
|
||||
{
|
||||
return c.end();
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// pair
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
@ -64,13 +64,13 @@ namespace range_detail
|
||||
{
|
||||
return p.second;
|
||||
}
|
||||
|
||||
|
||||
template< typename Iterator >
|
||||
inline Iterator boost_range_end( std::pair<Iterator,Iterator>& p )
|
||||
{
|
||||
return p.second;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// array
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
@ -78,13 +78,13 @@ namespace range_detail
|
||||
template< typename T, std::size_t sz >
|
||||
inline const T* boost_range_end( const T (&array)[sz] )
|
||||
{
|
||||
return range_detail::array_end<T,sz>( array );
|
||||
return range_detail::array_end<T,sz>( array );
|
||||
}
|
||||
|
||||
|
||||
template< typename T, std::size_t sz >
|
||||
inline T* boost_range_end( T (&array)[sz] )
|
||||
{
|
||||
return range_detail::array_end<T,sz>( array );
|
||||
return range_detail::array_end<T,sz>( array );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
@ -136,19 +136,19 @@ namespace range_detail
|
||||
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) && \
|
||||
!BOOST_WORKAROUND(__GNUC__, < 3) \
|
||||
/**/
|
||||
/**/
|
||||
} // namespace 'range_detail'
|
||||
#endif
|
||||
|
||||
template< class T >
|
||||
inline BOOST_DEDUCED_TYPENAME range_iterator<
|
||||
typename remove_const<T>::type >::type end( T& r )
|
||||
inline BOOST_DEDUCED_TYPENAME range_iterator<
|
||||
typename remove_const<T>::type >::type end( T& r )
|
||||
{
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) && \
|
||||
!BOOST_WORKAROUND(__GNUC__, < 3) \
|
||||
/**/
|
||||
using namespace range_detail;
|
||||
#endif
|
||||
#endif
|
||||
return boost_range_end( r );
|
||||
}
|
||||
|
||||
@ -159,7 +159,7 @@ inline BOOST_DEDUCED_TYPENAME range_const_iterator<T>::type end( const T& r )
|
||||
!BOOST_WORKAROUND(__GNUC__, < 3) \
|
||||
/**/
|
||||
using namespace range_detail;
|
||||
#endif
|
||||
#endif
|
||||
return boost_range_end( r );
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ namespace boost
|
||||
#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||
|
||||
template< class C >
|
||||
inline BOOST_DEDUCED_TYPENAME range_reverse_result_iterator<C>::type
|
||||
inline BOOST_DEDUCED_TYPENAME range_reverse_result_iterator<C>::type
|
||||
rbegin( C& c )
|
||||
{
|
||||
return BOOST_DEDUCED_TYPENAME range_reverse_result_iterator<C>::type( end( c ) );
|
||||
@ -35,18 +35,18 @@ rbegin( C& c )
|
||||
#else
|
||||
|
||||
template< class C >
|
||||
inline BOOST_DEDUCED_TYPENAME range_reverse_iterator<
|
||||
typename remove_const<C>::type >::type
|
||||
inline BOOST_DEDUCED_TYPENAME range_reverse_iterator<
|
||||
typename remove_const<C>::type >::type
|
||||
rbegin( C& c )
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_reverse_iterator<
|
||||
typename remove_const<C>::type >::type
|
||||
typedef BOOST_DEDUCED_TYPENAME range_reverse_iterator<
|
||||
typename remove_const<C>::type >::type
|
||||
iter_type;
|
||||
return iter_type( end( c ) );
|
||||
}
|
||||
|
||||
template< class C >
|
||||
inline BOOST_DEDUCED_TYPENAME range_const_reverse_iterator<C>::type
|
||||
inline BOOST_DEDUCED_TYPENAME range_const_reverse_iterator<C>::type
|
||||
rbegin( const C& c )
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_const_reverse_iterator<C>::type
|
||||
|
@ -22,31 +22,31 @@
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
||||
#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||
|
||||
template< class C >
|
||||
inline BOOST_DEDUCED_TYPENAME range_reverse_result_iterator<C>::type
|
||||
inline BOOST_DEDUCED_TYPENAME range_reverse_result_iterator<C>::type
|
||||
rend( C& c )
|
||||
{
|
||||
return BOOST_DEDUCED_TYPENAME range_reverse_result_iterator<C>::type( begin( c ) );
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
|
||||
template< class C >
|
||||
inline BOOST_DEDUCED_TYPENAME range_reverse_iterator<
|
||||
typename remove_const<C>::type >::type
|
||||
inline BOOST_DEDUCED_TYPENAME range_reverse_iterator<
|
||||
typename remove_const<C>::type >::type
|
||||
rend( C& c )
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_reverse_iterator<
|
||||
typename remove_const<C>::type >::type
|
||||
typedef BOOST_DEDUCED_TYPENAME range_reverse_iterator<
|
||||
typename remove_const<C>::type >::type
|
||||
iter_type;
|
||||
return iter_type( begin( c ) );
|
||||
}
|
||||
|
||||
template< class C >
|
||||
inline BOOST_DEDUCED_TYPENAME range_const_reverse_iterator<C>::type
|
||||
inline BOOST_DEDUCED_TYPENAME range_const_reverse_iterator<C>::type
|
||||
rend( const C& c )
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_const_reverse_iterator<C>::type
|
||||
|
@ -21,47 +21,47 @@
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace range_detail
|
||||
{
|
||||
template< class T >
|
||||
struct add_unsigned;
|
||||
namespace range_detail
|
||||
{
|
||||
template< class T >
|
||||
struct add_unsigned;
|
||||
|
||||
template<>
|
||||
struct add_unsigned<short>
|
||||
{
|
||||
typedef unsigned short type;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct add_unsigned<int>
|
||||
{
|
||||
typedef unsigned int type;
|
||||
};
|
||||
template<>
|
||||
struct add_unsigned<short>
|
||||
{
|
||||
typedef unsigned short type;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct add_unsigned<long>
|
||||
{
|
||||
typedef unsigned long type;
|
||||
};
|
||||
template<>
|
||||
struct add_unsigned<int>
|
||||
{
|
||||
typedef unsigned int type;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct add_unsigned<long>
|
||||
{
|
||||
typedef unsigned long type;
|
||||
};
|
||||
|
||||
#ifdef BOOST_HAS_LONG_LONG
|
||||
|
||||
template<>
|
||||
struct add_unsigned<long long>
|
||||
{
|
||||
typedef unsigned long long type;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct add_unsigned<long long>
|
||||
{
|
||||
typedef unsigned long long type;
|
||||
};
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
template< class T >
|
||||
struct range_size
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_detail::add_unsigned<
|
||||
BOOST_DEDUCED_TYPENAME range_difference<T>::type >::type
|
||||
type;
|
||||
};
|
||||
template< class T >
|
||||
struct range_size
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_detail::add_unsigned<
|
||||
BOOST_DEDUCED_TYPENAME range_difference<T>::type >::type
|
||||
type;
|
||||
};
|
||||
}
|
||||
*/
|
||||
|
||||
@ -77,13 +77,13 @@ namespace boost
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// default
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
template< typename C >
|
||||
struct range_size
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME C::size_type type;
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// pair
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@ -93,7 +93,7 @@ namespace boost
|
||||
{
|
||||
typedef std::size_t type;
|
||||
};
|
||||
|
||||
|
||||
template< typename Iterator >
|
||||
struct range_size< const std::pair<Iterator,Iterator> >
|
||||
{
|
||||
|
@ -26,13 +26,13 @@
|
||||
|
||||
namespace boost
|
||||
{
|
||||
template< class T >
|
||||
template< class T >
|
||||
struct range_value
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME iterator_value<
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<T>::type >::type
|
||||
type;
|
||||
};
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME iterator_value<
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<T>::type >::type
|
||||
type;
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
@ -45,13 +45,13 @@ namespace boost
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// default
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
template< typename C >
|
||||
struct range_value
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME C::value_type type;
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// pair
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@ -59,15 +59,15 @@ namespace boost
|
||||
template< typename Iterator >
|
||||
struct range_value< std::pair<Iterator,Iterator> >
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME
|
||||
typedef BOOST_DEDUCED_TYPENAME
|
||||
iterator_value<Iterator>::type type;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
template< typename Iterator >
|
||||
struct range_value< const std::pair<Iterator,Iterator> >
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME
|
||||
typedef BOOST_DEDUCED_TYPENAME
|
||||
iterator_value<Iterator>::type type;
|
||||
};
|
||||
|
||||
@ -86,7 +86,7 @@ namespace boost
|
||||
{
|
||||
typedef const T type;
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// string
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
@ -27,72 +27,72 @@
|
||||
template< class Rng >
|
||||
typename boost::range_result_iterator<Rng>::type foo_algo( Rng& r )
|
||||
{
|
||||
//
|
||||
// This will only compile for Rng = UDT if the qualified calls
|
||||
// find boost_range_XXX via ADL.
|
||||
//
|
||||
return boost::size(r) == 0u ? boost::begin(r) : boost::end(r);
|
||||
//
|
||||
// This will only compile for Rng = UDT if the qualified calls
|
||||
// find boost_range_XXX via ADL.
|
||||
//
|
||||
return boost::size(r) == 0u ? boost::begin(r) : boost::end(r);
|
||||
}
|
||||
|
||||
namespace Foo
|
||||
{
|
||||
//
|
||||
// Our sample UDT
|
||||
//
|
||||
struct X
|
||||
{
|
||||
typedef std::vector<int> data_t;
|
||||
typedef data_t::iterator iterator;
|
||||
typedef data_t::const_iterator const_iterator;
|
||||
typedef data_t::size_type size_type;
|
||||
//
|
||||
// Our sample UDT
|
||||
//
|
||||
struct X
|
||||
{
|
||||
typedef std::vector<int> data_t;
|
||||
typedef data_t::iterator iterator;
|
||||
typedef data_t::const_iterator const_iterator;
|
||||
typedef data_t::size_type size_type;
|
||||
|
||||
data_t vec;
|
||||
data_t vec;
|
||||
|
||||
void push_back( int i )
|
||||
{ vec.push_back(i); }
|
||||
};
|
||||
void push_back( int i )
|
||||
{ vec.push_back(i); }
|
||||
};
|
||||
|
||||
//
|
||||
// The required functions. No type-traits need
|
||||
// to be defined because X defines the proper set of
|
||||
// nested types.
|
||||
//
|
||||
inline X::iterator boost_range_begin( X& x )
|
||||
{
|
||||
return x.vec.begin();
|
||||
}
|
||||
//
|
||||
// The required functions. No type-traits need
|
||||
// to be defined because X defines the proper set of
|
||||
// nested types.
|
||||
//
|
||||
inline X::iterator boost_range_begin( X& x )
|
||||
{
|
||||
return x.vec.begin();
|
||||
}
|
||||
|
||||
|
||||
inline X::const_iterator boost_range_begin( const X& x )
|
||||
{
|
||||
return x.vec.begin();
|
||||
}
|
||||
|
||||
|
||||
inline X::const_iterator boost_range_begin( const X& x )
|
||||
{
|
||||
return x.vec.begin();
|
||||
}
|
||||
|
||||
|
||||
inline X::iterator boost_range_end( X& x )
|
||||
{
|
||||
return x.vec.end();
|
||||
}
|
||||
{
|
||||
return x.vec.end();
|
||||
}
|
||||
|
||||
inline X::const_iterator boost_range_end( const X& x )
|
||||
{
|
||||
return x.vec.end();
|
||||
}
|
||||
inline X::const_iterator boost_range_end( const X& x )
|
||||
{
|
||||
return x.vec.end();
|
||||
}
|
||||
|
||||
inline X::size_type boost_range_size( const X& x )
|
||||
{
|
||||
return x.vec.size();
|
||||
}
|
||||
inline X::size_type boost_range_size( const X& x )
|
||||
{
|
||||
return x.vec.size();
|
||||
}
|
||||
}
|
||||
|
||||
void check_extension()
|
||||
{
|
||||
Foo::X x;
|
||||
x.push_back(3);
|
||||
const Foo::X x2;
|
||||
Foo::X x;
|
||||
x.push_back(3);
|
||||
const Foo::X x2;
|
||||
|
||||
foo_algo( x );
|
||||
foo_algo( x2 );
|
||||
foo_algo( x );
|
||||
foo_algo( x2 );
|
||||
}
|
||||
|
||||
using boost::unit_test::test_suite;
|
||||
|
Reference in New Issue
Block a user