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