|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r77990 - in trunk: boost/range boost/range/algorithm boost/range/algorithm_ext boost/range/detail libs/range/doc libs/range/doc/reference libs/range/test libs/range/test/algorithm_test
From: neil_at_[hidden]
Date: 2012-04-15 07:52:02
Author: neilgroves
Date: 2012-04-15 07:52:01 EDT (Sun, 15 Apr 2012)
New Revision: 77990
URL: http://svn.boost.org/trac/boost/changeset/77990
Log:
[boost][range] - Trac 5971 - size() should return an unsigned type.
Text files modified:
trunk/boost/range/algorithm/equal.hpp | 20 ++++++++--
trunk/boost/range/algorithm_ext/copy_n.hpp | 8 ++--
trunk/boost/range/detail/size_type.hpp | 33 ++++------------
trunk/boost/range/size.hpp | 6 +-
trunk/boost/range/size_type.hpp | 56 +++++++++++++++++------------
trunk/libs/range/doc/mfc_atl.qbk | 2
trunk/libs/range/doc/portability.qbk | 2
trunk/libs/range/doc/reference/semantics.qbk | 2
trunk/libs/range/doc/reference/synopsis.qbk | 28 +++++++-------
trunk/libs/range/doc/reference/utilities.qbk | 74 ++++++++++++++++++++--------------------
trunk/libs/range/doc/style.qbk | 8 ++--
trunk/libs/range/doc/upgrade.qbk | 6 +++
trunk/libs/range/test/algorithm_test/for_each.cpp | 2
trunk/libs/range/test/extension_size.cpp | 2
14 files changed, 130 insertions(+), 119 deletions(-)
Modified: trunk/boost/range/algorithm/equal.hpp
==============================================================================
--- trunk/boost/range/algorithm/equal.hpp (original)
+++ trunk/boost/range/algorithm/equal.hpp 2012-04-15 07:52:01 EDT (Sun, 15 Apr 2012)
@@ -31,7 +31,7 @@
IteratorCategoryTag1,
IteratorCategoryTag2 )
{
- do
+ while (true)
{
// 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
@@ -46,7 +46,12 @@
return false;
// 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
// inequality has been detected.
@@ -66,7 +71,7 @@
IteratorCategoryTag1,
IteratorCategoryTag2 )
{
- do
+ while (true)
{
// 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
@@ -81,7 +86,12 @@
return false;
// 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
// inequality has been detected.
@@ -182,7 +192,7 @@
}
} // namespace range
- using range::equal;
+ using ::boost::range::equal;
} // namespace boost
#endif // include guard
Modified: trunk/boost/range/algorithm_ext/copy_n.hpp
==============================================================================
--- trunk/boost/range/algorithm_ext/copy_n.hpp (original)
+++ trunk/boost/range/algorithm_ext/copy_n.hpp 2012-04-15 07:52:01 EDT (Sun, 15 Apr 2012)
@@ -30,15 +30,15 @@
///
/// \pre SinglePassRange is a model of the SinglePassRangeConcept
/// \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 >
inline OutputIterator copy_n(const SinglePassRange& rng, Size n, OutputIterator out)
{
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_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)
*out = *source;
@@ -47,7 +47,7 @@
}
} // namespace range
- using range::copy_n;
+ using ::boost::range::copy_n;
} // namespace boost
#endif // include guard
Modified: trunk/boost/range/detail/size_type.hpp
==============================================================================
--- trunk/boost/range/detail/size_type.hpp (original)
+++ trunk/boost/range/detail/size_type.hpp 2012-04-15 07:52:01 EDT (Sun, 15 Apr 2012)
@@ -17,52 +17,37 @@
// missing partial specialization workaround.
//////////////////////////////////////////////////////////////////////////////
-namespace boost
+namespace boost
{
- namespace range_detail
- {
+ namespace range_detail
+ {
template< typename T >
- struct range_size_type_;
-
- template<>
- struct range_size_type_<std_container_>
+ struct range_size_type_
{
template< typename C >
struct pts
{
- 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_>
+ struct range_size_type_<std_container_>
{
- template< typename A >
+ template< typename C >
struct pts
{
- typedef std::size_t type;
+ typedef BOOST_RANGE_DEDUCED_TYPENAME C::size_type type;
};
};
+ }
-
- }
-
template< typename C >
class range_size
{
typedef typename range_detail::range<C>::type c_type;
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;
};
}
Modified: trunk/boost/range/size.hpp
==============================================================================
--- trunk/boost/range/size.hpp (original)
+++ trunk/boost/range/size.hpp 2012-04-15 07:52:01 EDT (Sun, 15 Apr 2012)
@@ -18,7 +18,7 @@
#include <boost/range/config.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
-#include <boost/range/difference_type.hpp>
+#include <boost/range/size_type.hpp>
#include <boost/assert.hpp>
namespace boost
@@ -26,7 +26,7 @@
namespace range_detail
{
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)
{
BOOST_ASSERT( (boost::end(rng) - boost::begin(rng)) >= 0 &&
@@ -36,7 +36,7 @@
}
template<class SinglePassRange>
- inline BOOST_DEDUCED_TYPENAME range_difference<SinglePassRange>::type
+ inline BOOST_DEDUCED_TYPENAME range_size<const SinglePassRange>::type
size(const SinglePassRange& rng)
{
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) && \
Modified: trunk/boost/range/size_type.hpp
==============================================================================
--- trunk/boost/range/size_type.hpp (original)
+++ trunk/boost/range/size_type.hpp 2012-04-15 07:52:01 EDT (Sun, 15 Apr 2012)
@@ -16,11 +16,13 @@
#endif
#include <boost/range/config.hpp>
-
+#include <boost/range/difference_type.hpp>
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
#include <boost/range/detail/size_type.hpp>
#else
+#include <boost/utility.hpp>
+#include <boost/type_traits/make_unsigned.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <cstddef>
#include <utility>
@@ -33,36 +35,44 @@
//////////////////////////////////////////////////////////////////////////
// default
//////////////////////////////////////////////////////////////////////////
-
- template< typename C >
- struct range_size
+
+ template<typename T>
+ class has_size_type
{
- typedef BOOST_DEDUCED_TYPENAME C::size_type 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);
};
-
- //////////////////////////////////////////////////////////////////////////
- // pair
- //////////////////////////////////////////////////////////////////////////
-
- template< typename Iterator >
- struct range_size< std::pair<Iterator,Iterator> >
+
+ template<typename C, typename Enabler=void>
+ struct range_size
{
- typedef std::size_t type;
+ typedef BOOST_DEDUCED_TYPENAME make_unsigned<
+ BOOST_DEDUCED_TYPENAME range_difference<C>::type
+ >::type type;
};
-
- //////////////////////////////////////////////////////////////////////////
- // array
- //////////////////////////////////////////////////////////////////////////
-
- template< typename T, std::size_t sz >
- struct range_size< T[sz] >
+
+ template<typename C>
+ struct range_size<
+ C,
+ BOOST_DEDUCED_TYPENAME enable_if<has_size_type<C>, void>::type
+ >
{
- typedef std::size_t type;
+ typedef BOOST_DEDUCED_TYPENAME C::size_type type;
};
+
}
template< class T >
- struct range_size :
+ struct range_size :
detail::range_size<T>
{ };
@@ -70,7 +80,7 @@
struct range_size<const T >
: detail::range_size<T>
{ };
-
+
} // namespace boost
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Modified: trunk/libs/range/doc/mfc_atl.qbk
==============================================================================
--- trunk/libs/range/doc/mfc_atl.qbk (original)
+++ trunk/libs/range/doc/mfc_atl.qbk 2012-04-15 07:52:01 EDT (Sun, 15 Apr 2012)
@@ -41,7 +41,7 @@
* Boost C++ Libraries Version 1.34.0 or later (no compilation required)
* Visual C++ 7.1 or later (for MFC and ATL)
-
+
[endsect]
[section:mfc_ranges MFC Ranges]
Modified: trunk/libs/range/doc/portability.qbk
==============================================================================
--- trunk/libs/range/doc/portability.qbk (original)
+++ trunk/libs/range/doc/portability.qbk 2012-04-15 07:52:01 EDT (Sun, 15 Apr 2012)
@@ -19,7 +19,7 @@
# 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:
* 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.
Modified: trunk/libs/range/doc/reference/semantics.qbk
==============================================================================
--- trunk/libs/range/doc/reference/semantics.qbk (original)
+++ trunk/libs/range/doc/reference/semantics.qbk 2012-04-15 07:52:01 EDT (Sun, 15 Apr 2012)
@@ -128,7 +128,7 @@
]
[
[`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]
[constant time]
]
Modified: trunk/libs/range/doc/reference/synopsis.qbk
==============================================================================
--- trunk/libs/range/doc/reference/synopsis.qbk (original)
+++ trunk/libs/range/doc/reference/synopsis.qbk 2012-04-15 07:52:01 EDT (Sun, 15 Apr 2012)
@@ -20,10 +20,10 @@
template< class T >
struct range_reference;
-
+
template< class T >
struct range_pointer;
-
+
template< class T >
struct range_category;
@@ -92,11 +92,11 @@
template< class T >
typename range_reverse_iterator<const T>::type
rend( const T& r );
-
+
//
// Random Access Range functions
//
-
+
template< class T >
typename range_difference<T>::type
size( const T& r );
@@ -106,42 +106,42 @@
//
template< class T >
- typename range_iterator<const T>::type
+ typename range_iterator<const T>::type
const_begin( const T& r );
template< class T >
- typename range_iterator<const T>::type
+ typename range_iterator<const T>::type
const_end( const T& r );
template< class T >
- typename range_reverse_iterator<const T>::type
+ typename range_reverse_iterator<const T>::type
const_rbegin( const T& r );
template< class T >
- typename range_reverse_iterator<const T>::type
+ typename range_reverse_iterator<const T>::type
const_rend( const T& r );
-
+
//
// String utilities
//
-
+
template< class T >
iterator_range< ... see below ... >
as_literal( T& r );
-
+
template< class T >
iterator_range< ... see below ... >
as_literal( const T& r );
-
+
template< class T >
iterator_range< typename range_iterator<T>::type >
as_array( T& r );
-
+
template< class T >
iterator_range< typename range_iterator<const T>::type >
as_array( const T& r );
-} // namespace 'boost'
+} // namespace 'boost'
``
[endsect]
Modified: trunk/libs/range/doc/reference/utilities.qbk
==============================================================================
--- trunk/libs/range/doc/reference/utilities.qbk (original)
+++ trunk/libs/range/doc/reference/utilities.qbk 2012-04-15 07:52:01 EDT (Sun, 15 Apr 2012)
@@ -40,23 +40,23 @@
public: // construction, assignment
template< class ForwardTraversalIterator2 >
iterator_range( ForwardTraversalIterator2 Begin, ForwardTraversalIterator2 End );
-
+
template< class ForwardRange >
iterator_range( ForwardRange& r );
-
+
template< class ForwardRange >
iterator_range( const ForwardRange& r );
-
+
template< class ForwardRange >
iterator_range& operator=( ForwardRange& r );
template< class ForwardRange >
iterator_range& operator=( const ForwardRange& r );
-
+
public: // Forward Range functions
iterator begin() const;
iterator end() const;
-
+
public: // convenience
operator unspecified_bool_type() const;
bool equal( const iterator_range& ) const;
@@ -65,25 +65,25 @@
iterator_range& advance_begin(difference_type n);
iterator_range& advance_end(difference_type n);
bool empty() const;
- // for Random Access Range only:
+ // for Random Access Range only:
reference operator[]( difference_type at ) const;
value_type operator()( difference_type at ) const;
size_type size() const;
};
-
+
// stream output
template< class ForwardTraversalIterator, class T, class Traits >
- std::basic_ostream<T,Traits>&
+ std::basic_ostream<T,Traits>&
operator<<( std::basic_ostream<T,Traits>& Os,
const iterator_range<ForwardTraversalIterator>& r );
// comparison
template< class ForwardTraversalIterator, class ForwardTraversalIterator2 >
- bool operator==( const iterator_range<ForwardTraversalIterator>& l,
+ bool operator==( const iterator_range<ForwardTraversalIterator>& l,
const iterator_range<ForwardTraversalIterator2>& r );
template< class ForwardTraversalIterator, class ForwardRange >
- bool operator==( const iterator_range<ForwardTraversalIterator>& l,
+ bool operator==( const iterator_range<ForwardTraversalIterator>& l,
const ForwardRange& r );
template< class ForwardTraversalIterator, class ForwardRange >
@@ -91,11 +91,11 @@
const iterator_range<ForwardTraversalIterator>& r );
template< class ForwardTraversalIterator, class ForwardTraversalIterator2 >
- bool operator!=( const iterator_range<ForwardTraversalIterator>& l,
+ bool operator!=( const iterator_range<ForwardTraversalIterator>& l,
const iterator_range<ForwardTraversalIterator2>& r );
template< class ForwardTraversalIterator, class ForwardRange >
- bool operator!=( const iterator_range<ForwardTraversalIterator>& l,
+ bool operator!=( const iterator_range<ForwardTraversalIterator>& l,
const ForwardRange& r );
template< class ForwardTraversalIterator, class ForwardRange >
@@ -103,23 +103,23 @@
const iterator_range<ForwardTraversalIterator>& r );
template< class ForwardTraversalIterator, class ForwardTraversalIterator2 >
- bool operator<( const iterator_range<ForwardTraversalIterator>& l,
+ bool operator<( const iterator_range<ForwardTraversalIterator>& l,
const iterator_range<ForwardTraversalIterator2>& r );
template< class ForwardTraversalIterator, class ForwardRange >
- bool operator<( const iterator_range<ForwardTraversalIterator>& l,
+ bool operator<( const iterator_range<ForwardTraversalIterator>& l,
const ForwardRange& r );
template< class ForwardTraversalIterator, class ForwardRange >
bool operator<( const ForwardRange& l,
const iterator_range<ForwardTraversalIterator>& r );
-
+
// external construction
template< class ForwardTraversalIterator >
iterator_range< ForwardTraversalIterator >
- make_iterator_range( ForwardTraversalIterator Begin,
+ make_iterator_range( ForwardTraversalIterator Begin,
ForwardTraversalIterator End );
-
+
template< class ForwardRange >
iterator_range< typename range_iterator<ForwardRange>::type >
make_iterator_range( ForwardRange& r );
@@ -127,25 +127,25 @@
template< class ForwardRange >
iterator_range< typename range_iterator<const ForwardRange>::type >
make_iterator_range( const ForwardRange& r );
-
+
template< class Range >
iterator_range< typename range_iterator<Range>::type >
make_iterator_range( Range& r,
typename range_difference<Range>::type advance_begin,
typename range_difference<Range>::type advance_end );
-
+
template< class Range >
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_end );
-
+
// convenience
template< class Sequence, class ForwardRange >
Sequence copy_range( const ForwardRange& r );
-
+
} // 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).
@@ -177,7 +177,7 @@
``
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 );
``
@@ -209,46 +209,46 @@
template< class ForwardRange >
class sub_range : public iterator_range< typename range_iterator<ForwardRange>::type >
{
- public:
+ public:
typedef typename range_iterator<ForwardRange>::type iterator;
typedef typename range_iterator<const ForwardRange>::type const_iterator;
typedef typename iterator_difference<iterator>::type difference_type;
-
+
public: // construction, assignment
template< class ForwardTraversalIterator >
sub_range( ForwardTraversalIterator Begin, ForwardTraversalIterator End );
template< class ForwardRange2 >
sub_range( ForwardRange2& r );
-
+
template< class ForwardRange2 >
sub_range( const Range2& r );
-
+
template< class ForwardRange2 >
sub_range& operator=( ForwardRange2& r );
template< class ForwardRange2 >
- sub_range& operator=( const ForwardRange2& r );
-
- public: // Forward Range functions
+ sub_range& operator=( const ForwardRange2& r );
+
+ public: // Forward Range functions
iterator begin();
const_iterator begin() const;
iterator end();
- const_iterator end() const;
-
- public: // convenience
+ const_iterator end() const;
+
+ public: // convenience
value_type& front();
const value_type& front() const;
value_type& back();
const value_type& back() const;
- // for Random Access Range only:
+ // for Random Access Range only:
value_type& operator[]( size_type at );
const value_type& operator[]( size_type at ) const;
-
+
public:
// rest of interface inherited from iterator_range
};
-
+
} // namespace 'boost'
``
Modified: trunk/libs/range/doc/style.qbk
==============================================================================
--- trunk/libs/range/doc/style.qbk (original)
+++ trunk/libs/range/doc/style.qbk 2012-04-15 07:52:01 EDT (Sun, 15 Apr 2012)
@@ -13,7 +13,7 @@
* Readable Range
* Writeable Range
* Swappable Range
- * Lvalue Range
+ * Lvalue Range
* [*/Traversal/] category:
* __single_pass_range__
* __forward_range__
@@ -25,7 +25,7 @@
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
-* 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.
@@ -37,7 +37,7 @@
template< class RandomAccessTraversalReadableWritableIterator >
void sort( RandomAccessTraversalReadableWritableIterator first,
RandomAccessTraversalReadableWritableIterator last );
-``
+``
For ranges the interface becomes
@@ -45,6 +45,6 @@
template< class RandomAccessReadableWritableRange >
void sort( RandomAccessReadableWritableRange& r );
``
-
+
[endsect]
Modified: trunk/libs/range/doc/upgrade.qbk
==============================================================================
--- trunk/libs/range/doc/upgrade.qbk (original)
+++ trunk/libs/range/doc/upgrade.qbk 2012-04-15 07:52:01 EDT (Sun, 15 Apr 2012)
@@ -5,6 +5,12 @@
/]
[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]
# __size__ in addition to supporting __random_access_range__ now also supports extensibility via calls to the unqualified `range_calculate_size(rng)` function.
Modified: trunk/libs/range/test/algorithm_test/for_each.cpp
==============================================================================
--- trunk/libs/range/test/algorithm_test/for_each.cpp (original)
+++ trunk/libs/range/test/algorithm_test/for_each.cpp 2012-04-15 07:52:01 EDT (Sun, 15 Apr 2012)
@@ -44,7 +44,7 @@
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));
- BOOST_CHECK_EQUAL( boost::udistance(rng), result_fn.invocation_count() );
+ BOOST_CHECK_EQUAL( boost::udistance(rng), result_fn2.invocation_count() );
// Test the constant version
const SinglePassRange& cref_rng = rng;
Modified: trunk/libs/range/test/extension_size.cpp
==============================================================================
--- trunk/libs/range/test/extension_size.cpp (original)
+++ trunk/libs/range/test/extension_size.cpp 2012-04-15 07:52:01 EDT (Sun, 15 Apr 2012)
@@ -40,7 +40,7 @@
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)
{
return 2u;
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk