[boost][range] - Trac 5971 - size() should return an unsigned type.

[SVN r77990]
This commit is contained in:
Neil Groves
2012-04-15 11:52:01 +00:00
parent 1cb6a99c80
commit 11238e4c19
14 changed files with 136 additions and 125 deletions

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

@ -31,7 +31,7 @@ namespace boost
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 @@ namespace boost
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 @@ namespace boost
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 @@ namespace boost
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 boost
}
} // namespace range
using range::equal;
using ::boost::range::equal;
} // namespace boost
#endif // include guard

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 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 range::copy_n;
using ::boost::range::copy_n;
} // namespace boost
#endif // include guard

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

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

@ -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 boost
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 @@ namespace boost
}
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)) && \

View File

@ -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 @@ namespace boost
//////////////////////////////////////////////////////////////////////////
// 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
{
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>
{ };
@ -70,7 +80,7 @@ namespace boost
struct range_size<const T >
: detail::range_size<T>
{ };
} // namespace boost
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION