[boost][range] - Merge trac resolutions from the trunk. The most notable change is the alteration of the size type to be unsigned. This is a potentially breaking change.

[SVN r78860]
This commit is contained in:
Neil Groves
2012-06-08 22:59:54 +00:00
parent 2f3d82be9f
commit dc46fc13ab
27 changed files with 155 additions and 147 deletions

View File

@ -41,7 +41,7 @@ BOOST_FOREACH (CList<CString> *theList, myArray)
* Boost C++ Libraries Version 1.34.0 or later (no compilation required) * Boost C++ Libraries Version 1.34.0 or later (no compilation required)
* Visual C++ 7.1 or later (for MFC and ATL) * Visual C++ 7.1 or later (for MFC and ATL)
[endsect] [endsect]
[section:mfc_ranges MFC Ranges] [section:mfc_ranges MFC Ranges]

View File

@ -19,7 +19,7 @@ For maximum portability you should follow these guidelines:
# use __const_begin__`()` and __const_end__`()` whenever your code by intention is read-only; this will also solve most rvalue problems, # use __const_begin__`()` and __const_end__`()` whenever your code by intention is read-only; this will also solve most rvalue problems,
# do not rely on ADL: # do not rely on ADL:
* if you overload functions, include that header before the headers in this library, * if you overload functions, include that header before the headers in this library,
* put all overloads in namespace boost. * put all overloads in namespace boost.

View File

@ -128,7 +128,7 @@
] ]
[ [
[`size(x)`] [`size(x)`]
[`range_difference<X>::type`] [`range_size<X>::type`]
[`range_calculate_size(x)` which by default is `boost::end(x) - boost::begin(x)`. Users may supply alternative implementations by implementing `range_calculate_size(x)` so that it will be found via ADL] [`range_calculate_size(x)` which by default is `boost::end(x) - boost::begin(x)`. Users may supply alternative implementations by implementing `range_calculate_size(x)` so that it will be found via ADL]
[constant time] [constant time]
] ]

View File

@ -20,10 +20,10 @@ namespace boost
template< class T > template< class T >
struct range_reference; struct range_reference;
template< class T > template< class T >
struct range_pointer; struct range_pointer;
template< class T > template< class T >
struct range_category; struct range_category;
@ -92,11 +92,11 @@ namespace boost
template< class T > template< class T >
typename range_reverse_iterator<const T>::type typename range_reverse_iterator<const T>::type
rend( const T& r ); rend( const T& r );
// //
// Random Access Range functions // Random Access Range functions
// //
template< class T > template< class T >
typename range_difference<T>::type typename range_difference<T>::type
size( const T& r ); size( const T& r );
@ -106,42 +106,42 @@ namespace boost
// //
template< class T > template< class T >
typename range_iterator<const T>::type typename range_iterator<const T>::type
const_begin( const T& r ); const_begin( const T& r );
template< class T > template< class T >
typename range_iterator<const T>::type typename range_iterator<const T>::type
const_end( const T& r ); const_end( const T& r );
template< class T > template< class T >
typename range_reverse_iterator<const T>::type typename range_reverse_iterator<const T>::type
const_rbegin( const T& r ); const_rbegin( const T& r );
template< class T > template< class T >
typename range_reverse_iterator<const T>::type typename range_reverse_iterator<const T>::type
const_rend( const T& r ); const_rend( const T& r );
// //
// String utilities // String utilities
// //
template< class T > template< class T >
iterator_range< ... see below ... > iterator_range< ... see below ... >
as_literal( T& r ); as_literal( T& r );
template< class T > template< class T >
iterator_range< ... see below ... > iterator_range< ... see below ... >
as_literal( const T& r ); as_literal( const T& r );
template< class T > template< class T >
iterator_range< typename range_iterator<T>::type > iterator_range< typename range_iterator<T>::type >
as_array( T& r ); as_array( T& r );
template< class T > template< class T >
iterator_range< typename range_iterator<const T>::type > iterator_range< typename range_iterator<const T>::type >
as_array( const T& r ); as_array( const T& r );
} // namespace 'boost' } // namespace 'boost'
`` ``
[endsect] [endsect]

View File

@ -40,23 +40,23 @@ namespace boost
public: // construction, assignment public: // construction, assignment
template< class ForwardTraversalIterator2 > template< class ForwardTraversalIterator2 >
iterator_range( ForwardTraversalIterator2 Begin, ForwardTraversalIterator2 End ); iterator_range( ForwardTraversalIterator2 Begin, ForwardTraversalIterator2 End );
template< class ForwardRange > template< class ForwardRange >
iterator_range( ForwardRange& r ); iterator_range( ForwardRange& r );
template< class ForwardRange > template< class ForwardRange >
iterator_range( const ForwardRange& r ); iterator_range( const ForwardRange& r );
template< class ForwardRange > template< class ForwardRange >
iterator_range& operator=( ForwardRange& r ); iterator_range& operator=( ForwardRange& r );
template< class ForwardRange > template< class ForwardRange >
iterator_range& operator=( const ForwardRange& r ); iterator_range& operator=( const ForwardRange& r );
public: // Forward Range functions public: // Forward Range functions
iterator begin() const; iterator begin() const;
iterator end() const; iterator end() const;
public: // convenience public: // convenience
operator unspecified_bool_type() const; operator unspecified_bool_type() const;
bool equal( const iterator_range& ) const; bool equal( const iterator_range& ) const;
@ -65,25 +65,25 @@ namespace boost
iterator_range& advance_begin(difference_type n); iterator_range& advance_begin(difference_type n);
iterator_range& advance_end(difference_type n); iterator_range& advance_end(difference_type n);
bool empty() const; bool empty() const;
// for Random Access Range only: // for Random Access Range only:
reference operator[]( difference_type at ) const; reference operator[]( difference_type at ) const;
value_type operator()( difference_type at ) const; value_type operator()( difference_type at ) const;
size_type size() const; size_type size() const;
}; };
// stream output // stream output
template< class ForwardTraversalIterator, class T, class Traits > template< class ForwardTraversalIterator, class T, class Traits >
std::basic_ostream<T,Traits>& std::basic_ostream<T,Traits>&
operator<<( std::basic_ostream<T,Traits>& Os, operator<<( std::basic_ostream<T,Traits>& Os,
const iterator_range<ForwardTraversalIterator>& r ); const iterator_range<ForwardTraversalIterator>& r );
// comparison // comparison
template< class ForwardTraversalIterator, class ForwardTraversalIterator2 > template< class ForwardTraversalIterator, class ForwardTraversalIterator2 >
bool operator==( const iterator_range<ForwardTraversalIterator>& l, bool operator==( const iterator_range<ForwardTraversalIterator>& l,
const iterator_range<ForwardTraversalIterator2>& r ); const iterator_range<ForwardTraversalIterator2>& r );
template< class ForwardTraversalIterator, class ForwardRange > template< class ForwardTraversalIterator, class ForwardRange >
bool operator==( const iterator_range<ForwardTraversalIterator>& l, bool operator==( const iterator_range<ForwardTraversalIterator>& l,
const ForwardRange& r ); const ForwardRange& r );
template< class ForwardTraversalIterator, class ForwardRange > template< class ForwardTraversalIterator, class ForwardRange >
@ -91,11 +91,11 @@ namespace boost
const iterator_range<ForwardTraversalIterator>& r ); const iterator_range<ForwardTraversalIterator>& r );
template< class ForwardTraversalIterator, class ForwardTraversalIterator2 > template< class ForwardTraversalIterator, class ForwardTraversalIterator2 >
bool operator!=( const iterator_range<ForwardTraversalIterator>& l, bool operator!=( const iterator_range<ForwardTraversalIterator>& l,
const iterator_range<ForwardTraversalIterator2>& r ); const iterator_range<ForwardTraversalIterator2>& r );
template< class ForwardTraversalIterator, class ForwardRange > template< class ForwardTraversalIterator, class ForwardRange >
bool operator!=( const iterator_range<ForwardTraversalIterator>& l, bool operator!=( const iterator_range<ForwardTraversalIterator>& l,
const ForwardRange& r ); const ForwardRange& r );
template< class ForwardTraversalIterator, class ForwardRange > template< class ForwardTraversalIterator, class ForwardRange >
@ -103,23 +103,23 @@ namespace boost
const iterator_range<ForwardTraversalIterator>& r ); const iterator_range<ForwardTraversalIterator>& r );
template< class ForwardTraversalIterator, class ForwardTraversalIterator2 > template< class ForwardTraversalIterator, class ForwardTraversalIterator2 >
bool operator<( const iterator_range<ForwardTraversalIterator>& l, bool operator<( const iterator_range<ForwardTraversalIterator>& l,
const iterator_range<ForwardTraversalIterator2>& r ); const iterator_range<ForwardTraversalIterator2>& r );
template< class ForwardTraversalIterator, class ForwardRange > template< class ForwardTraversalIterator, class ForwardRange >
bool operator<( const iterator_range<ForwardTraversalIterator>& l, bool operator<( const iterator_range<ForwardTraversalIterator>& l,
const ForwardRange& r ); const ForwardRange& r );
template< class ForwardTraversalIterator, class ForwardRange > template< class ForwardTraversalIterator, class ForwardRange >
bool operator<( const ForwardRange& l, bool operator<( const ForwardRange& l,
const iterator_range<ForwardTraversalIterator>& r ); const iterator_range<ForwardTraversalIterator>& r );
// external construction // external construction
template< class ForwardTraversalIterator > template< class ForwardTraversalIterator >
iterator_range< ForwardTraversalIterator > iterator_range< ForwardTraversalIterator >
make_iterator_range( ForwardTraversalIterator Begin, make_iterator_range( ForwardTraversalIterator Begin,
ForwardTraversalIterator End ); ForwardTraversalIterator End );
template< class ForwardRange > template< class ForwardRange >
iterator_range< typename range_iterator<ForwardRange>::type > iterator_range< typename range_iterator<ForwardRange>::type >
make_iterator_range( ForwardRange& r ); make_iterator_range( ForwardRange& r );
@ -127,25 +127,25 @@ namespace boost
template< class ForwardRange > template< class ForwardRange >
iterator_range< typename range_iterator<const ForwardRange>::type > iterator_range< typename range_iterator<const ForwardRange>::type >
make_iterator_range( const ForwardRange& r ); make_iterator_range( const ForwardRange& r );
template< class Range > template< class Range >
iterator_range< typename range_iterator<Range>::type > iterator_range< typename range_iterator<Range>::type >
make_iterator_range( Range& r, make_iterator_range( Range& r,
typename range_difference<Range>::type advance_begin, typename range_difference<Range>::type advance_begin,
typename range_difference<Range>::type advance_end ); typename range_difference<Range>::type advance_end );
template< class Range > template< class Range >
iterator_range< typename range_iterator<const Range>::type > iterator_range< typename range_iterator<const Range>::type >
make_iterator_range( const Range& r, make_iterator_range( const Range& r,
typename range_difference<const Range>::type advance_begin, typename range_difference<const Range>::type advance_begin,
typename range_difference<const Range>::type advance_end ); typename range_difference<const Range>::type advance_end );
// convenience // convenience
template< class Sequence, class ForwardRange > template< class Sequence, class ForwardRange >
Sequence copy_range( const ForwardRange& r ); Sequence copy_range( const ForwardRange& r );
} // namespace 'boost' } // namespace 'boost'
`` ``
If an instance of `iterator_range` is constructed by a client with two iterators, the client must ensure that the two iterators delimit a valid closed-open range [begin,end). If an instance of `iterator_range` is constructed by a client with two iterators, the client must ensure that the two iterators delimit a valid closed-open range [begin,end).
@ -177,7 +177,7 @@ It is worth noticing that the templated constructors and assignment operators al
`` ``
iterator_range make_iterator_range( Range& r, iterator_range make_iterator_range( Range& r,
typename range_difference<Range>::type advance_begin, typename range_difference<Range>::type advance_begin,
typename range_difference<Range>::type advance_end ); typename range_difference<Range>::type advance_end );
`` ``
@ -209,46 +209,46 @@ namespace boost
template< class ForwardRange > template< class ForwardRange >
class sub_range : public iterator_range< typename range_iterator<ForwardRange>::type > class sub_range : public iterator_range< typename range_iterator<ForwardRange>::type >
{ {
public: public:
typedef typename range_iterator<ForwardRange>::type iterator; typedef typename range_iterator<ForwardRange>::type iterator;
typedef typename range_iterator<const ForwardRange>::type const_iterator; typedef typename range_iterator<const ForwardRange>::type const_iterator;
typedef typename iterator_difference<iterator>::type difference_type; typedef typename iterator_difference<iterator>::type difference_type;
public: // construction, assignment public: // construction, assignment
template< class ForwardTraversalIterator > template< class ForwardTraversalIterator >
sub_range( ForwardTraversalIterator Begin, ForwardTraversalIterator End ); sub_range( ForwardTraversalIterator Begin, ForwardTraversalIterator End );
template< class ForwardRange2 > template< class ForwardRange2 >
sub_range( ForwardRange2& r ); sub_range( ForwardRange2& r );
template< class ForwardRange2 > template< class ForwardRange2 >
sub_range( const Range2& r ); sub_range( const Range2& r );
template< class ForwardRange2 > template< class ForwardRange2 >
sub_range& operator=( ForwardRange2& r ); sub_range& operator=( ForwardRange2& r );
template< class ForwardRange2 > template< class ForwardRange2 >
sub_range& operator=( const ForwardRange2& r ); sub_range& operator=( const ForwardRange2& r );
public: // Forward Range functions public: // Forward Range functions
iterator begin(); iterator begin();
const_iterator begin() const; const_iterator begin() const;
iterator end(); iterator end();
const_iterator end() const; const_iterator end() const;
public: // convenience public: // convenience
value_type& front(); value_type& front();
const value_type& front() const; const value_type& front() const;
value_type& back(); value_type& back();
const value_type& back() const; const value_type& back() const;
// for Random Access Range only: // for Random Access Range only:
value_type& operator[]( size_type at ); value_type& operator[]( size_type at );
const value_type& operator[]( size_type at ) const; const value_type& operator[]( size_type at ) const;
public: public:
// rest of interface inherited from iterator_range // rest of interface inherited from iterator_range
}; };
} // namespace 'boost' } // namespace 'boost'
`` ``

View File

@ -13,7 +13,7 @@ Since ranges are characterized by a specific underlying iterator type, we get a
* Readable Range * Readable Range
* Writeable Range * Writeable Range
* Swappable Range * Swappable Range
* Lvalue Range * Lvalue Range
* [*/Traversal/] category: * [*/Traversal/] category:
* __single_pass_range__ * __single_pass_range__
* __forward_range__ * __forward_range__
@ -25,7 +25,7 @@ Notice how we have used the categories from the __new_style_iterators__.
Notice that an iterator (and therefore an range) has one [*/traversal/] property and one or more properties from the [*/value access/] category. So in reality we will mostly talk about mixtures such as Notice that an iterator (and therefore an range) has one [*/traversal/] property and one or more properties from the [*/value access/] category. So in reality we will mostly talk about mixtures such as
* Random Access Readable Writeable Range * Random Access Readable Writeable Range
* Forward Lvalue Range * Forward Lvalue Range
By convention, we should always specify the [*/traversal/] property first as done above. This seems reasonable since there will only be one [*/traversal/] property, but perhaps many [*/value access/] properties. By convention, we should always specify the [*/traversal/] property first as done above. This seems reasonable since there will only be one [*/traversal/] property, but perhaps many [*/value access/] properties.
@ -37,7 +37,7 @@ As another example, consider how we specify the interface of `std::sort()`. Algo
template< class RandomAccessTraversalReadableWritableIterator > template< class RandomAccessTraversalReadableWritableIterator >
void sort( RandomAccessTraversalReadableWritableIterator first, void sort( RandomAccessTraversalReadableWritableIterator first,
RandomAccessTraversalReadableWritableIterator last ); RandomAccessTraversalReadableWritableIterator last );
`` ``
For ranges the interface becomes For ranges the interface becomes
@ -45,6 +45,6 @@ For ranges the interface becomes
template< class RandomAccessReadableWritableRange > template< class RandomAccessReadableWritableRange >
void sort( RandomAccessReadableWritableRange& r ); void sort( RandomAccessReadableWritableRange& r );
`` ``
[endsect] [endsect]

View File

@ -5,6 +5,12 @@
/] /]
[section:upgrade Upgrade version of Boost.Range] [section:upgrade Upgrade version of Boost.Range]
[section:upgrade_from_1_49 Upgrade from version 1.49]
# __size__ now returns the type Rng::size_type if the range has size_type;
otherwise range_size<Rng>::type is used. This is the distance type promoted to
an unsigned type.
[section:upgrade_from_1_45 Upgrade from version 1.45] [section:upgrade_from_1_45 Upgrade from version 1.45]
# __size__ in addition to supporting __random_access_range__ now also supports extensibility via calls to the unqualified `range_calculate_size(rng)` function. # __size__ in addition to supporting __random_access_range__ now also supports extensibility via calls to the unqualified `range_calculate_size(rng)` function.

20
include/boost/range/algorithm/equal.hpp Executable file → Normal file
View File

@ -31,7 +31,7 @@ namespace boost
IteratorCategoryTag1, IteratorCategoryTag1,
IteratorCategoryTag2 ) IteratorCategoryTag2 )
{ {
do while (true)
{ {
// If we have reached the end of the left range then this is // If we have reached the end of the left range then this is
// the end of the loop. They are equal if and only if we have // the end of the loop. They are equal if and only if we have
@ -46,7 +46,12 @@ namespace boost
return false; return false;
// continue looping if and only if the values are equal // continue looping if and only if the values are equal
} while(*first1++ == *first2++); if (*first1 != *first2)
break;
++first1;
++first2;
}
// Reaching this line in the algorithm indicates that a value // Reaching this line in the algorithm indicates that a value
// inequality has been detected. // inequality has been detected.
@ -66,7 +71,7 @@ namespace boost
IteratorCategoryTag1, IteratorCategoryTag1,
IteratorCategoryTag2 ) IteratorCategoryTag2 )
{ {
do while (true)
{ {
// If we have reached the end of the left range then this is // If we have reached the end of the left range then this is
// the end of the loop. They are equal if and only if we have // the end of the loop. They are equal if and only if we have
@ -81,7 +86,12 @@ namespace boost
return false; return false;
// continue looping if and only if the values are equal // continue looping if and only if the values are equal
} while(pred(*first1++, *first2++)); if (!pred(*first1, *first2))
break;
++first1;
++first2;
}
// Reaching this line in the algorithm indicates that a value // Reaching this line in the algorithm indicates that a value
// inequality has been detected. // inequality has been detected.
@ -182,7 +192,7 @@ namespace boost
} }
} // namespace range } // namespace range
using range::equal; using ::boost::range::equal;
} // namespace boost } // namespace boost
#endif // include guard #endif // include guard

View File

@ -14,7 +14,6 @@
#include <boost/range/end.hpp> #include <boost/range/end.hpp>
#include <boost/range/concepts.hpp> #include <boost/range/concepts.hpp>
#include <boost/ref.hpp> #include <boost/ref.hpp>
#include <boost/utility.hpp>
#include <algorithm> #include <algorithm>
#if BOOST_WORKAROUND(BOOST_MSVC, == 1600) #if BOOST_WORKAROUND(BOOST_MSVC, == 1600)

8
include/boost/range/algorithm_ext/copy_n.hpp Executable file → Normal file
View File

@ -30,15 +30,15 @@ namespace boost
/// ///
/// \pre SinglePassRange is a model of the SinglePassRangeConcept /// \pre SinglePassRange is a model of the SinglePassRangeConcept
/// \pre OutputIterator is a model of the OutputIteratorConcept /// \pre OutputIterator is a model of the OutputIteratorConcept
/// \pre 0 <= n < distance(rng) /// \pre 0 <= n <= distance(rng)
template< class SinglePassRange, class Size, class OutputIterator > template< class SinglePassRange, class Size, class OutputIterator >
inline OutputIterator copy_n(const SinglePassRange& rng, Size n, OutputIterator out) inline OutputIterator copy_n(const SinglePassRange& rng, Size n, OutputIterator out)
{ {
BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange> )); BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange> ));
BOOST_ASSERT( n < static_cast<Size>(boost::distance(rng)) ); BOOST_ASSERT( n <= static_cast<Size>(::boost::distance(rng)) );
BOOST_ASSERT( n >= static_cast<Size>(0) ); BOOST_ASSERT( n >= static_cast<Size>(0) );
BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange>::type source = boost::begin(rng); BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange>::type source = ::boost::begin(rng);
for (Size i = 0; i < n; ++i, ++out, ++source) for (Size i = 0; i < n; ++i, ++out, ++source)
*out = *source; *out = *source;
@ -47,7 +47,7 @@ inline OutputIterator copy_n(const SinglePassRange& rng, Size n, OutputIterator
} }
} // namespace range } // namespace range
using range::copy_n; using ::boost::range::copy_n;
} // namespace boost } // namespace boost
#endif // include guard #endif // include guard

View File

@ -74,7 +74,7 @@ namespace boost
#endif #endif
template< class T > template< class T >
inline long is_char_ptr( T /* r */ ) inline long is_char_ptr( const T& /* r */ )
{ {
return 0L; return 0L;
} }

1
include/boost/range/counting_range.hpp Executable file → Normal file
View File

@ -18,7 +18,6 @@
#include <boost/range/iterator_range_core.hpp> #include <boost/range/iterator_range_core.hpp>
#include <boost/range/value_type.hpp> #include <boost/range/value_type.hpp>
#include <boost/iterator/counting_iterator.hpp> #include <boost/iterator/counting_iterator.hpp>
#include <boost/utility.hpp>
namespace boost namespace boost
{ {

View File

@ -11,7 +11,6 @@
#define BOOST_RANGE_DETAIL_ANY_ITERATOR_HPP_INCLUDED #define BOOST_RANGE_DETAIL_ANY_ITERATOR_HPP_INCLUDED
#include <boost/cast.hpp> #include <boost/cast.hpp>
#include <boost/utility.hpp>
#include <boost/mpl/and.hpp> #include <boost/mpl/and.hpp>
#include <boost/mpl/or.hpp> #include <boost/mpl/or.hpp>
#include <boost/mpl/not.hpp> #include <boost/mpl/not.hpp>

View File

@ -13,7 +13,7 @@
#include <boost/array.hpp> #include <boost/array.hpp>
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/static_assert.hpp> #include <boost/static_assert.hpp>
#include <boost/utility.hpp> #include <boost/noncopyable.hpp>
namespace boost namespace boost
{ {

View File

@ -23,7 +23,7 @@
#include <boost/range/empty.hpp> #include <boost/range/empty.hpp>
#include <boost/range/detail/demote_iterator_traversal_tag.hpp> #include <boost/range/detail/demote_iterator_traversal_tag.hpp>
#include <boost/range/value_type.hpp> #include <boost/range/value_type.hpp>
#include <boost/utility.hpp> #include <boost/next_prior.hpp>
namespace boost namespace boost
{ {

41
include/boost/range/detail/size_type.hpp Executable file → Normal file
View File

@ -17,12 +17,19 @@
// missing partial specialization workaround. // missing partial specialization workaround.
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
namespace boost namespace boost
{ {
namespace range_detail namespace range_detail
{ {
template< typename T > template< typename T >
struct range_size_type_; struct range_size_type_
{
template< typename C >
struct pts
{
typedef std::size_t type;
};
};
template<> template<>
struct range_size_type_<std_container_> struct range_size_type_<std_container_>
@ -33,36 +40,14 @@ namespace boost
typedef BOOST_RANGE_DEDUCED_TYPENAME C::size_type type; typedef BOOST_RANGE_DEDUCED_TYPENAME C::size_type type;
}; };
}; };
}
template<>
struct range_size_type_<std_pair_>
{
template< typename P >
struct pts
{
typedef std::size_t type;
};
};
template<>
struct range_size_type_<array_>
{
template< typename A >
struct pts
{
typedef std::size_t type;
};
};
}
template< typename C > template< typename C >
class range_size class range_size
{ {
typedef typename range_detail::range<C>::type c_type; typedef typename range_detail::range<C>::type c_type;
public: public:
typedef typename range_detail::range_size_type_<c_type>::BOOST_NESTED_TEMPLATE pts<C>::type type; typedef typename range_detail::range_size_type_<c_type>::BOOST_NESTED_TEMPLATE pts<C>::type type;
}; };
} }

View File

@ -13,7 +13,7 @@
#include <boost/mpl/bool.hpp> #include <boost/mpl/bool.hpp>
#include <boost/mpl/has_xxx.hpp> #include <boost/mpl/has_xxx.hpp>
#include <boost/range/iterator.hpp> #include <boost/range/iterator.hpp>
#include <boost/utility.hpp> #include <boost/utility/enable_if.hpp>
namespace boost namespace boost
{ {

2
include/boost/range/numeric.hpp Executable file → Normal file
View File

@ -40,7 +40,7 @@ namespace boost
template< class SinglePassRange, class Value > template< class SinglePassRange, class Value >
inline Value accumulate( const SinglePassRange& rng, Value init ) inline Value accumulate( const SinglePassRange& rng, Value init )
{ {
BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange> )); BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange> ));
return std::accumulate( boost::begin(rng), boost::end(rng), init ); return std::accumulate( boost::begin(rng), boost::end(rng), init );
} }

View File

@ -18,7 +18,7 @@
#include <boost/range/config.hpp> #include <boost/range/config.hpp>
#include <boost/range/begin.hpp> #include <boost/range/begin.hpp>
#include <boost/range/end.hpp> #include <boost/range/end.hpp>
#include <boost/range/difference_type.hpp> #include <boost/range/size_type.hpp>
#include <boost/assert.hpp> #include <boost/assert.hpp>
namespace boost namespace boost
@ -26,7 +26,7 @@ namespace boost
namespace range_detail namespace range_detail
{ {
template<class SinglePassRange> template<class SinglePassRange>
inline BOOST_DEDUCED_TYPENAME range_difference<SinglePassRange>::type inline BOOST_DEDUCED_TYPENAME range_size<const SinglePassRange>::type
range_calculate_size(const SinglePassRange& rng) range_calculate_size(const SinglePassRange& rng)
{ {
BOOST_ASSERT( (boost::end(rng) - boost::begin(rng)) >= 0 && BOOST_ASSERT( (boost::end(rng) - boost::begin(rng)) >= 0 &&
@ -36,7 +36,7 @@ namespace boost
} }
template<class SinglePassRange> template<class SinglePassRange>
inline BOOST_DEDUCED_TYPENAME range_difference<SinglePassRange>::type inline BOOST_DEDUCED_TYPENAME range_size<const SinglePassRange>::type
size(const SinglePassRange& rng) size(const SinglePassRange& rng)
{ {
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) && \ #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) && \

View File

@ -16,11 +16,13 @@
#endif #endif
#include <boost/range/config.hpp> #include <boost/range/config.hpp>
#include <boost/range/difference_type.hpp>
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
#include <boost/range/detail/size_type.hpp> #include <boost/range/detail/size_type.hpp>
#else #else
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/make_unsigned.hpp>
#include <boost/type_traits/remove_const.hpp> #include <boost/type_traits/remove_const.hpp>
#include <cstddef> #include <cstddef>
#include <utility> #include <utility>
@ -33,36 +35,44 @@ namespace boost
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// default // default
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
template< typename C > template<typename T>
class has_size_type
{
typedef char no_type;
struct yes_type { char dummy[2]; };
template<typename C>
static yes_type test(BOOST_DEDUCED_TYPENAME C::size_type x);
template<typename C, typename Arg>
static no_type test(Arg x);
public:
static const bool value = sizeof(test<T>(0)) == sizeof(yes_type);
};
template<typename C, typename Enabler=void>
struct range_size struct range_size
{
typedef BOOST_DEDUCED_TYPENAME make_unsigned<
BOOST_DEDUCED_TYPENAME range_difference<C>::type
>::type type;
};
template<typename C>
struct range_size<
C,
BOOST_DEDUCED_TYPENAME enable_if<has_size_type<C>, void>::type
>
{ {
typedef BOOST_DEDUCED_TYPENAME C::size_type type; typedef BOOST_DEDUCED_TYPENAME C::size_type type;
}; };
//////////////////////////////////////////////////////////////////////////
// pair
//////////////////////////////////////////////////////////////////////////
template< typename Iterator >
struct range_size< std::pair<Iterator,Iterator> >
{
typedef std::size_t type;
};
//////////////////////////////////////////////////////////////////////////
// array
//////////////////////////////////////////////////////////////////////////
template< typename T, std::size_t sz >
struct range_size< T[sz] >
{
typedef std::size_t type;
};
} }
template< class T > template< class T >
struct range_size : struct range_size :
detail::range_size<T> detail::range_size<T>
{ }; { };
@ -70,7 +80,7 @@ namespace boost
struct range_size<const T > struct range_size<const T >
: detail::range_size<T> : detail::range_size<T>
{ }; { };
} // namespace boost } // namespace boost
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION

View File

@ -172,9 +172,9 @@ void check_adl_conformance()
BOOST_CHECK_EQUAL( boost_test::begin( r6 ), global_namespace ); BOOST_CHECK_EQUAL( boost_test::begin( r6 ), global_namespace );
} }
#include <boost/test/included/unit_test_framework.hpp> #include <boost/test/included/unit_test.hpp>
using boost::unit_test_framework::test_suite; using boost::unit_test::test_suite;
test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite* init_unit_test_suite( int argc, char* argv[] )
{ {

View File

@ -44,7 +44,7 @@ namespace boost
BOOST_CHECK_EQUAL( boost::udistance(rng), result_fn.invocation_count() ); BOOST_CHECK_EQUAL( boost::udistance(rng), result_fn.invocation_count() );
fn_t result_fn2 = boost::for_each(boost::make_iterator_range(rng), fn_t(rng)); fn_t result_fn2 = boost::for_each(boost::make_iterator_range(rng), fn_t(rng));
BOOST_CHECK_EQUAL( boost::udistance(rng), result_fn.invocation_count() ); BOOST_CHECK_EQUAL( boost::udistance(rng), result_fn2.invocation_count() );
// Test the constant version // Test the constant version
const SinglePassRange& cref_rng = rng; const SinglePassRange& cref_rng = rng;

View File

@ -18,7 +18,7 @@
#include <boost/range/begin.hpp> #include <boost/range/begin.hpp>
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include <boost/test/test_tools.hpp> #include <boost/test/test_tools.hpp>
#include <boost/test/included/unit_test_framework.hpp> #include <boost/test/included/unit_test.hpp>
namespace mock_std namespace mock_std
{ {
@ -104,12 +104,12 @@ namespace
} }
} }
using boost::unit_test_framework::test_suite; using boost::unit_test::test_suite;
boost::unit_test_framework::test_suite* boost::unit_test::test_suite*
init_unit_test_suite( int argc, char* argv[] ) init_unit_test_suite( int argc, char* argv[] )
{ {
boost::unit_test_framework::test_suite* test = BOOST_TEST_SUITE( "Range Test Suite - begin() ADL namespace barrier" ); boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "Range Test Suite - begin() ADL namespace barrier" );
test->add( BOOST_TEST_CASE( &test_range_begin ) ); test->add( BOOST_TEST_CASE( &test_range_begin ) );

View File

@ -53,9 +53,9 @@ void compat1()
iterator_of< std::vector<int> >::type i = v.begin(); iterator_of< std::vector<int> >::type i = v.begin();
} }
#include <boost/test/included/unit_test_framework.hpp> #include <boost/test/included/unit_test.hpp>
using boost::unit_test_framework::test_suite; using boost::unit_test::test_suite;
test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite* init_unit_test_suite( int argc, char* argv[] )
{ {

4
test/compat3.cpp Executable file → Normal file
View File

@ -53,9 +53,9 @@ void compat1()
iterator_of< std::vector<int> >::type i = v.begin(); iterator_of< std::vector<int> >::type i = v.begin();
} }
#include <boost/test/included/unit_test_framework.hpp> #include <boost/test/included/unit_test.hpp>
using boost::unit_test_framework::test_suite; using boost::unit_test::test_suite;
test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite* init_unit_test_suite( int argc, char* argv[] )
{ {

View File

@ -18,7 +18,7 @@
#include <boost/range/end.hpp> #include <boost/range/end.hpp>
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include <boost/test/test_tools.hpp> #include <boost/test/test_tools.hpp>
#include <boost/test/included/unit_test_framework.hpp> #include <boost/test/included/unit_test.hpp>
namespace mock_std namespace mock_std
{ {
@ -104,12 +104,12 @@ namespace
} }
} }
using boost::unit_test_framework::test_suite; using boost::unit_test::test_suite;
boost::unit_test_framework::test_suite* boost::unit_test::test_suite*
init_unit_test_suite( int argc, char* argv[] ) init_unit_test_suite( int argc, char* argv[] )
{ {
boost::unit_test_framework::test_suite* test = BOOST_TEST_SUITE( "Range Test Suite - end() ADL namespace barrier" ); boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "Range Test Suite - end() ADL namespace barrier" );
test->add( BOOST_TEST_CASE( &test_range_end_adl_avoidance ) ); test->add( BOOST_TEST_CASE( &test_range_end_adl_avoidance ) );

View File

@ -40,7 +40,7 @@ namespace boost_range_extension_size_test
impl_t m_impl; impl_t m_impl;
}; };
inline boost::range_difference<std::list<int> >::type inline boost::range_size<std::list<int> >::type
range_calculate_size(const FooWithoutSize& rng) range_calculate_size(const FooWithoutSize& rng)
{ {
return 2u; return 2u;