Compare commits

..

12 Commits

Author SHA1 Message Date
d46a4468e1 Branch for 2nd try at V2 removal
[SVN r77497]
2012-03-23 12:04:44 +00:00
1cb6a99c80 eliminated unit_test_framework
[SVN r74719]
2011-10-05 09:13:05 +00:00
c4bd4bf4ce Remove tabs.
[SVN r72190]
2011-05-26 18:23:57 +00:00
41b76f8f5c [boost][range] - Ticket 5236 - Improved test coverage to ensure that the result for a random access strided range is consistent with that of a bidirectional strided range.
[SVN r72108]
2011-05-22 22:15:14 +00:00
846f11a96c [boost][range] - Ticket 5236 - Strided reversing past begin issue resolved.
[SVN r72107]
2011-05-22 22:06:30 +00:00
8810c4c4aa [boost][range] - Ticket 5547 - Boost.Range join() ambiguous with Boost.Algorithm join() function. Put the Boost.Range join function into the boost::range namespace and brought out with 'using'
[SVN r72106]
2011-05-22 21:19:53 +00:00
91428c2110 [boost][range] - Ticket 5530 - adaptor example fails to compile. This change adds tests for all of the .cpp example files for the range adaptors, and fixes a few small issues with the examples shown by the new tests.
[SVN r72104]
2011-05-22 21:03:01 +00:00
44c26a3356 [boost][range] - Ticket 5486 - Removal of unnecessary variables from adjacent_filtered_range. This removes the requirement for the predicate to be default constructible.
[SVN r72102]
2011-05-22 20:33:06 +00:00
b06fca8378 [boost][range] - Ticket 5556 - is_sorted namespace issue under GCC 4.5
[SVN r72101]
2011-05-22 20:20:20 +00:00
3b3889b70f [boost][range] - Ticket 5485 - doubly defined BOOST_DEFINE_RANGE_ADAPTOR_1 macro.
[SVN r72098]
2011-05-22 20:01:12 +00:00
5ed6116490 [boost][range] - ticket 5544 - fix for termination of irange - done properly for negative step sizes.
[SVN r72097]
2011-05-22 19:59:59 +00:00
df1a3a334f [boost][range] - ticket 5544 - fix for termination of irange.
[SVN r72070]
2011-05-22 11:16:53 +00:00
25 changed files with 187 additions and 195 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)
* Visual C++ 7.1 or later (for MFC and ATL)
[endsect]
[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,
# 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.

View File

@ -128,7 +128,7 @@
]
[
[`size(x)`]
[`range_size<X>::type`]
[`range_difference<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]
]

View File

@ -20,10 +20,10 @@ namespace boost
template< class T >
struct range_reference;
template< class T >
struct range_pointer;
template< class T >
struct range_category;
@ -92,11 +92,11 @@ namespace boost
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 @@ namespace boost
//
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]

View File

@ -40,23 +40,23 @@ namespace boost
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 @@ namespace boost
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 @@ namespace boost
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 @@ namespace boost
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 @@ namespace boost
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 @@ It is worth noticing that the templated constructors and assignment operators al
``
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 @@ namespace boost
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'
``

View File

@ -13,7 +13,7 @@ Since ranges are characterized by a specific underlying iterator type, we get a
* Readable Range
* Writeable Range
* Swappable Range
* Lvalue Range
* Lvalue Range
* [*/Traversal/] category:
* __single_pass_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
* 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 @@ As another example, consider how we specify the interface of `std::sort()`. Algo
template< class RandomAccessTraversalReadableWritableIterator >
void sort( RandomAccessTraversalReadableWritableIterator first,
RandomAccessTraversalReadableWritableIterator last );
``
``
For ranges the interface becomes
@ -45,6 +45,6 @@ For ranges the interface becomes
template< class RandomAccessReadableWritableRange >
void sort( RandomAccessReadableWritableRange& r );
``
[endsect]

View File

@ -5,12 +5,6 @@
/]
[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.

View File

@ -15,7 +15,7 @@
# pragma once
#endif
#if _MSC_VER == 1300 // experiment
#if defined(_MSC_VER) && (_MSC_VER == 1300)
#include <boost/range/detail/collection_traits.hpp>
#include <boost/range/iterator_range.hpp>
@ -28,6 +28,6 @@
#include <boost/range/iterator_range.hpp>
#include <boost/range/sub_range.hpp>
#endif // _MSC_VER == 1300 // experiment
#endif // _MSC_VER == 1300
#endif

View File

@ -31,7 +31,7 @@ namespace boost
IteratorCategoryTag1,
IteratorCategoryTag2 )
{
while (true)
do
{
// 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,12 +46,7 @@ namespace boost
return false;
// continue looping if and only if the values are equal
if (*first1 != *first2)
break;
++first1;
++first2;
}
} while(*first1++ == *first2++);
// Reaching this line in the algorithm indicates that a value
// inequality has been detected.
@ -71,7 +66,7 @@ namespace boost
IteratorCategoryTag1,
IteratorCategoryTag2 )
{
while (true)
do
{
// 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
@ -86,12 +81,7 @@ namespace boost
return false;
// continue looping if and only if the values are equal
if (!pred(*first1, *first2))
break;
++first1;
++first2;
}
} while(pred(*first1++, *first2++));
// Reaching this line in the algorithm indicates that a value
// inequality has been detected.
@ -192,7 +182,7 @@ namespace boost
}
} // namespace range
using ::boost::range::equal;
using range::equal;
} // namespace boost
#endif // include guard

View File

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

View File

@ -30,15 +30,15 @@ namespace boost
///
/// \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 @@ inline OutputIterator copy_n(const SinglePassRange& rng, Size n, OutputIterator
}
} // namespace range
using ::boost::range::copy_n;
using range::copy_n;
} // namespace boost
#endif // include guard

View File

@ -25,7 +25,7 @@
#include <boost/detail/workaround.hpp>
#include <cstring>
#ifndef BOOST_NO_CWCHAR
#ifndef BOOST_NO_CWCHAR
#include <cwchar>
#endif
@ -38,72 +38,72 @@ namespace boost
return strlen( s );
}
#ifndef BOOST_NO_CWCHAR
#ifndef BOOST_NO_CWCHAR
inline std::size_t length( const wchar_t* s )
{
return wcslen( s );
}
#endif
#endif
//
// Remark: the compiler cannot choose between T* and T[sz]
// overloads, so we must put the T* internal to the
// unconstrained version.
//
//
inline bool is_char_ptr( char* )
{
return true;
}
inline bool is_char_ptr( const char* )
{
return true;
}
#ifndef BOOST_NO_CWCHAR
#ifndef BOOST_NO_CWCHAR
inline bool is_char_ptr( wchar_t* )
{
return true;
}
inline bool is_char_ptr( const wchar_t* )
{
return true;
}
#endif
template< class T >
inline long is_char_ptr( const T& /* r */ )
inline long is_char_ptr( T /* r */ )
{
return 0L;
}
template< class T >
inline iterator_range<T*>
inline iterator_range<T*>
make_range( T* const r, bool )
{
return iterator_range<T*>( r, r + length(r) );
}
template< class T >
inline iterator_range<BOOST_DEDUCED_TYPENAME range_iterator<T>::type>
inline iterator_range<BOOST_DEDUCED_TYPENAME range_iterator<T>::type>
make_range( T& r, long )
{
return boost::make_iterator_range( r );
}
}
template< class Range >
inline iterator_range<BOOST_DEDUCED_TYPENAME range_iterator<Range>::type>
inline iterator_range<BOOST_DEDUCED_TYPENAME range_iterator<Range>::type>
as_literal( Range& r )
{
return range_detail::make_range( r, range_detail::is_char_ptr(r) );
}
template< class Range >
inline iterator_range<BOOST_DEDUCED_TYPENAME range_iterator<const Range>::type>
inline iterator_range<BOOST_DEDUCED_TYPENAME range_iterator<const Range>::type>
as_literal( const Range& r )
{
return range_detail::make_range( r, range_detail::is_char_ptr(r) );
@ -112,9 +112,9 @@ namespace boost
template< class Char, std::size_t sz >
inline iterator_range<Char*> as_literal( Char (&arr)[sz] )
{
return range_detail::make_range( arr, range_detail::is_char_ptr(arr) );
return range_detail::make_range( arr, range_detail::is_char_ptr(arr) );
}
template< class Char, std::size_t sz >
inline iterator_range<const Char*> as_literal( const Char (&arr)[sz] )
{

View File

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

View File

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

View File

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

View File

@ -21,13 +21,13 @@
#include <wchar.h>
#endif
namespace boost
namespace boost
{
namespace range_detail
{
template <typename T>
inline void boost_range_silence_warning( const T& ) { }
/////////////////////////////////////////////////////////////////////
// end() help
/////////////////////////////////////////////////////////////////////
@ -36,7 +36,7 @@ namespace boost
{
return s + strlen( s );
}
#ifndef BOOST_NO_CWCHAR
inline const wchar_t* str_end( const wchar_t* s, const wchar_t* )
{
@ -51,7 +51,7 @@ namespace boost
;
return s;
}
#endif
#endif
template< class Char >
inline Char* str_end( Char* s )
@ -64,7 +64,7 @@ namespace boost
{
return boost_range_array + sz;
}
template< class T, std::size_t sz >
inline const T* array_end( const T BOOST_RANGE_ARRAY_REF()[sz] )
{
@ -74,7 +74,7 @@ namespace boost
/////////////////////////////////////////////////////////////////////
// size() help
/////////////////////////////////////////////////////////////////////
template< class Char >
inline std::size_t str_size( const Char* const& s )
{
@ -96,7 +96,7 @@ namespace boost
}
} // namespace 'range_detail'
} // namespace 'boost'

View File

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

View File

@ -17,19 +17,12 @@
// missing partial specialization workaround.
//////////////////////////////////////////////////////////////////////////////
namespace boost
namespace boost
{
namespace range_detail
{
namespace range_detail
{
template< typename T >
struct range_size_type_
{
template< typename C >
struct pts
{
typedef std::size_t type;
};
};
struct range_size_type_;
template<>
struct range_size_type_<std_container_>
@ -40,14 +33,36 @@ namespace boost
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 >
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;
};
}

View File

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

View File

@ -25,46 +25,46 @@
namespace boost
{
#if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
#if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
namespace range_detail_vc7_1
{
template< typename C, typename Sig = void(C) >
struct range_iterator
{
typedef BOOST_RANGE_DEDUCED_TYPENAME
mpl::eval_if_c< is_const<C>::value,
range_const_iterator< typename remove_const<C>::type >,
range_mutable_iterator<C> >::type type;
};
template< typename C, typename T >
struct range_iterator< C, void(T[]) >
{
typedef T* type;
};
}
#endif
namespace range_detail_vc7_1
{
template< typename C, typename Sig = void(C) >
struct range_iterator
{
typedef BOOST_RANGE_DEDUCED_TYPENAME
mpl::eval_if_c< is_const<C>::value,
range_const_iterator< typename remove_const<C>::type >,
range_mutable_iterator<C> >::type type;
};
template< typename C, typename T >
struct range_iterator< C, void(T[]) >
{
typedef T* type;
};
}
#endif
template< typename C >
struct range_iterator
{
#if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
typedef BOOST_RANGE_DEDUCED_TYPENAME
range_detail_vc7_1::range_iterator<C>::type type;
#else
typedef BOOST_RANGE_DEDUCED_TYPENAME
range_detail_vc7_1::range_iterator<C>::type type;
#else
typedef BOOST_RANGE_DEDUCED_TYPENAME
mpl::eval_if_c< is_const<C>::value,
typedef BOOST_RANGE_DEDUCED_TYPENAME
mpl::eval_if_c< is_const<C>::value,
range_const_iterator< typename remove_const<C>::type >,
range_mutable_iterator<C> >::type type;
#endif
#endif
};
} // namespace boost
//#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION

View File

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

View File

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

View File

@ -16,13 +16,11 @@
#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/enable_if.hpp>
#include <boost/type_traits/make_unsigned.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <cstddef>
#include <utility>
@ -35,44 +33,36 @@ namespace boost
//////////////////////////////////////////////////////////////////////////
// default
//////////////////////////////////////////////////////////////////////////
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>
template< typename C >
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;
};
//////////////////////////////////////////////////////////////////////////
// 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 >
struct range_size :
struct range_size :
detail::range_size<T>
{ };
@ -80,7 +70,7 @@ namespace boost
struct range_size<const T >
: detail::range_size<T>
{ };
} // namespace boost
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION

View File

@ -44,7 +44,7 @@ namespace boost
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_fn2.invocation_count() );
BOOST_CHECK_EQUAL( boost::udistance(rng), result_fn.invocation_count() );
// Test the constant version
const SinglePassRange& cref_rng = rng;

View File

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