forked from boostorg/range
[boost][range] Ticket 8702 - size_type detection
[SVN r85690]
This commit is contained in:
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <boost/range/config.hpp>
|
#include <boost/range/config.hpp>
|
||||||
#include <boost/range/difference_type.hpp>
|
#include <boost/range/difference_type.hpp>
|
||||||
|
#include <boost/range/concepts.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
|
||||||
@ -45,8 +46,8 @@ namespace boost
|
|||||||
template<typename C>
|
template<typename C>
|
||||||
static yes_type test(BOOST_DEDUCED_TYPENAME C::size_type x);
|
static yes_type test(BOOST_DEDUCED_TYPENAME C::size_type x);
|
||||||
|
|
||||||
template<typename C, typename Arg>
|
template<typename C>
|
||||||
static no_type test(Arg x);
|
static no_type test(...);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const bool value = sizeof(test<T>(0)) == sizeof(yes_type);
|
static const bool value = sizeof(test<T>(0)) == sizeof(yes_type);
|
||||||
@ -74,12 +75,16 @@ namespace boost
|
|||||||
template< class T >
|
template< class T >
|
||||||
struct range_size :
|
struct range_size :
|
||||||
detail::range_size<T>
|
detail::range_size<T>
|
||||||
{ };
|
{
|
||||||
|
BOOST_RANGE_CONCEPT_ASSERT((boost::SinglePassRangeConcept<T>));
|
||||||
|
};
|
||||||
|
|
||||||
template< class T >
|
template< class T >
|
||||||
struct range_size<const T >
|
struct range_size<const T >
|
||||||
: detail::range_size<T>
|
: detail::range_size<T>
|
||||||
{ };
|
{
|
||||||
|
BOOST_RANGE_CONCEPT_ASSERT((boost::SinglePassRangeConcept<T>));
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include <boost/range.hpp>
|
#include <boost/range.hpp>
|
||||||
#include <boost/test/test_tools.hpp>
|
#include <boost/test/test_tools.hpp>
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -27,6 +28,13 @@ namespace boost_range_extension_size_test
|
|||||||
class FooWithoutSize
|
class FooWithoutSize
|
||||||
{
|
{
|
||||||
typedef std::list<int> impl_t;
|
typedef std::list<int> impl_t;
|
||||||
|
|
||||||
|
BOOST_STATIC_ASSERT((
|
||||||
|
boost::is_same<
|
||||||
|
boost::range_size<std::list<int> >::type,
|
||||||
|
std::list<int>::size_type
|
||||||
|
>::value));
|
||||||
|
|
||||||
typedef impl_t::const_iterator const_iterator;
|
typedef impl_t::const_iterator const_iterator;
|
||||||
typedef impl_t::iterator iterator;
|
typedef impl_t::iterator iterator;
|
||||||
|
|
||||||
@ -39,12 +47,117 @@ namespace boost_range_extension_size_test
|
|||||||
private:
|
private:
|
||||||
impl_t m_impl;
|
impl_t m_impl;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline boost::range_size<std::list<int> >::type
|
template<typename SizeType>
|
||||||
range_calculate_size(const FooWithoutSize& rng)
|
class FooWithSize
|
||||||
{
|
{
|
||||||
return 2u;
|
public:
|
||||||
}
|
typedef SizeType size_type;
|
||||||
|
typedef boost::uint8_t* iterator;
|
||||||
|
typedef const boost::uint8_t* const_iterator;
|
||||||
|
|
||||||
|
const_iterator begin() const;
|
||||||
|
iterator begin();
|
||||||
|
const_iterator end() const;
|
||||||
|
iterator end();
|
||||||
|
};
|
||||||
|
|
||||||
|
BOOST_STATIC_ASSERT((
|
||||||
|
boost::is_same<
|
||||||
|
boost::uint8_t,
|
||||||
|
boost::range_size<FooWithSize<boost::uint8_t> >::type
|
||||||
|
>::value
|
||||||
|
));
|
||||||
|
|
||||||
|
BOOST_STATIC_ASSERT((
|
||||||
|
boost::is_same<
|
||||||
|
boost::uint16_t,
|
||||||
|
boost::range_size<FooWithSize<boost::uint16_t> >::type
|
||||||
|
>::value
|
||||||
|
));
|
||||||
|
|
||||||
|
BOOST_STATIC_ASSERT((
|
||||||
|
boost::is_same<
|
||||||
|
boost::uint32_t,
|
||||||
|
boost::range_size<FooWithSize<boost::uint32_t> >::type
|
||||||
|
>::value
|
||||||
|
));
|
||||||
|
|
||||||
|
BOOST_STATIC_ASSERT((
|
||||||
|
boost::is_same<
|
||||||
|
boost::uint64_t,
|
||||||
|
boost::range_size<FooWithSize<boost::uint64_t> >::type
|
||||||
|
>::value
|
||||||
|
));
|
||||||
|
|
||||||
|
class UdtSizeType
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef boost::uint16_t value_type;
|
||||||
|
|
||||||
|
UdtSizeType() : value_(0) { }
|
||||||
|
UdtSizeType(value_type value) : value_(value) { }
|
||||||
|
|
||||||
|
operator value_type() const { return value_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
value_type value_;
|
||||||
|
};
|
||||||
|
|
||||||
|
BOOST_STATIC_ASSERT((
|
||||||
|
boost::is_same<
|
||||||
|
UdtSizeType,
|
||||||
|
boost::range_size<FooWithSize<UdtSizeType> >::type
|
||||||
|
>::value
|
||||||
|
));
|
||||||
|
|
||||||
|
class Foo2WithoutSize
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
struct const_iterator
|
||||||
|
{
|
||||||
|
typedef std::forward_iterator_tag iterator_category;
|
||||||
|
typedef boost::int8_t difference_type;
|
||||||
|
typedef boost::int16_t value_type;
|
||||||
|
typedef value_type* pointer;
|
||||||
|
typedef value_type& reference;
|
||||||
|
|
||||||
|
reference operator*() const;
|
||||||
|
pointer operator->() const;
|
||||||
|
const_iterator& operator++();
|
||||||
|
const_iterator operator++(int);
|
||||||
|
bool operator==(const const_iterator&) const;
|
||||||
|
bool operator!=(const const_iterator&) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct iterator : const_iterator
|
||||||
|
{
|
||||||
|
typedef const value_type* pointer;
|
||||||
|
typedef const value_type& reference;
|
||||||
|
|
||||||
|
reference operator*() const;
|
||||||
|
pointer operator->() const;
|
||||||
|
|
||||||
|
iterator& operator++();
|
||||||
|
iterator operator++(int);
|
||||||
|
|
||||||
|
bool operator==(const iterator&) const;
|
||||||
|
bool operator!=(const iterator&) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
const_iterator begin() const;
|
||||||
|
iterator begin();
|
||||||
|
const_iterator end() const;
|
||||||
|
iterator end();
|
||||||
|
};
|
||||||
|
|
||||||
|
BOOST_STATIC_ASSERT((
|
||||||
|
boost::is_same<
|
||||||
|
boost::uint8_t,
|
||||||
|
boost::range_size<
|
||||||
|
::boost_range_extension_size_test::Foo2WithoutSize>::type
|
||||||
|
>::value
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
@ -60,6 +173,26 @@ namespace boost
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace boost_range_extension_size_test
|
||||||
|
{
|
||||||
|
inline boost::range_size<FooWithoutSize>::type
|
||||||
|
range_calculate_size(const FooWithoutSize& rng)
|
||||||
|
{
|
||||||
|
return 2u;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_STATIC_ASSERT((
|
||||||
|
boost::is_same<
|
||||||
|
typename boost::make_unsigned<std::ptrdiff_t>::type,
|
||||||
|
typename boost::range_size<
|
||||||
|
boost_range_extension_size_test::FooWithoutSize>::type
|
||||||
|
>::value
|
||||||
|
));
|
||||||
|
|
||||||
|
typedef boost::make_unsigned<std::ptrdiff_t>::type t1;
|
||||||
|
typedef boost::range_size<boost_range_extension_size_test::FooWithoutSize>::type t1;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user