More cleanups

[SVN r31860]
This commit is contained in:
Douglas Gregor
2005-12-01 15:00:34 +00:00
parent bd34ecb841
commit 32847c6b64
9 changed files with 250 additions and 250 deletions

View File

@ -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 // Test metafunctions
// //
boost::range_value< Foo::Pair<iter> >::type boost::range_value< Foo::Pair<iter> >::type
v = *boost::begin(pair); v = *boost::begin(pair);
boost::range_difference< Foo::Pair<iter> >::type boost::range_difference< Foo::Pair<iter> >::type
d = boost::end(pair) - boost::begin(pair); d = boost::end(pair) - boost::begin(pair);
} }

View File

@ -48,7 +48,7 @@ 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();
@ -143,7 +143,7 @@ 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) \

View File

@ -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

View File

@ -48,8 +48,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_end( C& c ) boost_range_end( C& c )
{ {
return c.end(); return c.end();
@ -142,7 +142,7 @@ 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 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) \

View File

@ -36,11 +36,11 @@ rbegin( C& c )
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 ) );
} }

View File

@ -36,11 +36,11 @@ rend( C& c )
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 ) );
} }

View File

@ -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<> template<>
struct add_unsigned<int> struct add_unsigned<int>
{ {
typedef unsigned int type; typedef unsigned int type;
}; };
template<> template<>
struct add_unsigned<long> struct add_unsigned<long>
{ {
typedef unsigned long type; 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;
}; };
} }
*/ */

View File

@ -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;
}; };
} }
/* /*

View File

@ -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 ) inline X::const_iterator boost_range_begin( const X& x )
{ {
return x.vec.begin(); 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;