forked from boostorg/range
[boost][range] - Update to relax preconditions for the strided adaptor, and numerous fixes to inspection report issues.
[SVN r67419]
This commit is contained in:
@ -1,3 +1,13 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2010. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
|
||||
#ifndef BOOST_RANGE_DEFINE_ADAPTOR_HPP_INCLUDED
|
||||
#define BOOST_RANGE_DEFINE_ADAPTOR_HPP_INCLUDED
|
||||
|
||||
|
@ -27,53 +27,53 @@ namespace boost
|
||||
std::size_t u;
|
||||
};
|
||||
|
||||
template< class RandomAccessRange >
|
||||
class sliced_range : public boost::iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<RandomAccessRange>::type >
|
||||
{
|
||||
typedef boost::iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<RandomAccessRange>::type > base_t;
|
||||
public:
|
||||
template<typename Rng, typename T, typename U>
|
||||
sliced_range(Rng& rng, T t, U u)
|
||||
: base_t(boost::make_iterator_range(rng, t, u - boost::size(rng)))
|
||||
{
|
||||
}
|
||||
};
|
||||
template< class RandomAccessRange >
|
||||
class sliced_range : public boost::iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<RandomAccessRange>::type >
|
||||
{
|
||||
typedef boost::iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<RandomAccessRange>::type > base_t;
|
||||
public:
|
||||
template<typename Rng, typename T, typename U>
|
||||
sliced_range(Rng& rng, T t, U u)
|
||||
: base_t(boost::make_iterator_range(rng, t, u - boost::size(rng)))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template< class RandomAccessRange >
|
||||
inline sliced_range<RandomAccessRange>
|
||||
slice( RandomAccessRange& rng, std::size_t t, std::size_t u )
|
||||
{
|
||||
BOOST_ASSERT( t <= u && "error in slice indices" );
|
||||
template< class RandomAccessRange >
|
||||
inline sliced_range<RandomAccessRange>
|
||||
slice( RandomAccessRange& rng, std::size_t t, std::size_t u )
|
||||
{
|
||||
BOOST_ASSERT( t <= u && "error in slice indices" );
|
||||
BOOST_ASSERT( static_cast<std::size_t>(boost::size(rng)) >= u &&
|
||||
"second slice index out of bounds" );
|
||||
"second slice index out of bounds" );
|
||||
|
||||
return sliced_range<RandomAccessRange>(rng, t, u);
|
||||
}
|
||||
return sliced_range<RandomAccessRange>(rng, t, u);
|
||||
}
|
||||
|
||||
template< class RandomAccessRange >
|
||||
inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<const RandomAccessRange>::type >
|
||||
slice( const RandomAccessRange& rng, std::size_t t, std::size_t u )
|
||||
{
|
||||
BOOST_ASSERT( t <= u && "error in slice indices" );
|
||||
BOOST_ASSERT( static_cast<std::size_t>(boost::size(rng)) >= u &&
|
||||
"second slice index out of bounds" );
|
||||
template< class RandomAccessRange >
|
||||
inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<const RandomAccessRange>::type >
|
||||
slice( const RandomAccessRange& rng, std::size_t t, std::size_t u )
|
||||
{
|
||||
BOOST_ASSERT( t <= u && "error in slice indices" );
|
||||
BOOST_ASSERT( static_cast<std::size_t>(boost::size(rng)) >= u &&
|
||||
"second slice index out of bounds" );
|
||||
|
||||
return sliced_range<const RandomAccessRange>(rng, t, u);
|
||||
}
|
||||
}
|
||||
|
||||
template< class RandomAccessRange >
|
||||
inline sliced_range<RandomAccessRange>
|
||||
operator|( RandomAccessRange& r, const sliced& f )
|
||||
{
|
||||
return sliced_range<RandomAccessRange>( r, f.t, f.u );
|
||||
}
|
||||
template< class RandomAccessRange >
|
||||
inline sliced_range<RandomAccessRange>
|
||||
operator|( RandomAccessRange& r, const sliced& f )
|
||||
{
|
||||
return sliced_range<RandomAccessRange>( r, f.t, f.u );
|
||||
}
|
||||
|
||||
template< class RandomAccessRange >
|
||||
inline sliced_range<const RandomAccessRange>
|
||||
operator|( const RandomAccessRange& r, const sliced& f )
|
||||
{
|
||||
return sliced_range<const RandomAccessRange>( r, f.t, f.u );
|
||||
}
|
||||
template< class RandomAccessRange >
|
||||
inline sliced_range<const RandomAccessRange>
|
||||
operator|( const RandomAccessRange& r, const sliced& f )
|
||||
{
|
||||
return sliced_range<const RandomAccessRange>( r, f.t, f.u );
|
||||
}
|
||||
|
||||
} // namespace adaptors
|
||||
} // namespace boost
|
||||
|
@ -30,34 +30,34 @@ namespace boost
|
||||
friend class iterator_core_access;
|
||||
|
||||
typedef iterator_adaptor<strided_iterator<BaseIterator>, BaseIterator> super_t;
|
||||
|
||||
|
||||
public:
|
||||
typedef BOOST_DEDUCED_TYPENAME std::iterator_traits<BaseIterator>::difference_type difference_type;
|
||||
|
||||
|
||||
strided_iterator() : m_stride() { }
|
||||
|
||||
|
||||
strided_iterator(const strided_iterator& other)
|
||||
: super_t(other), m_stride(other.m_stride) { }
|
||||
|
||||
|
||||
explicit strided_iterator(BaseIterator base_it, difference_type stride)
|
||||
: super_t(base_it), m_stride(stride) { }
|
||||
|
||||
|
||||
strided_iterator&
|
||||
operator=(const strided_iterator& other)
|
||||
{
|
||||
super_t::operator=(other);
|
||||
|
||||
|
||||
// Is the interoperation of the stride safe?
|
||||
m_stride = other.m_stride;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void increment() { std::advance(this->base_reference(), m_stride); }
|
||||
|
||||
|
||||
void decrement() { std::advance(this->base_reference(), -m_stride); }
|
||||
|
||||
|
||||
void advance(difference_type n) { std::advance(this->base_reference(), n * m_stride); }
|
||||
|
||||
|
||||
difference_type
|
||||
distance_to(const strided_iterator& other) const
|
||||
{
|
||||
@ -66,11 +66,11 @@ namespace boost
|
||||
|
||||
// Using the compiler generated copy constructor and
|
||||
// and assignment operator
|
||||
|
||||
|
||||
private:
|
||||
difference_type m_stride;
|
||||
};
|
||||
|
||||
|
||||
template<class BaseIterator> inline
|
||||
strided_iterator<BaseIterator>
|
||||
make_strided_iterator(
|
||||
@ -89,9 +89,31 @@ namespace boost
|
||||
public:
|
||||
template< typename Difference >
|
||||
strided_range(Difference stride, Rng& rng)
|
||||
: super_t(make_strided_iterator(boost::begin(rng), stride),
|
||||
make_strided_iterator(boost::end(rng), stride))
|
||||
: super_t(make_first(rng, stride), make_last(rng, stride))
|
||||
{
|
||||
BOOST_ASSERT( stride >= 0 );
|
||||
}
|
||||
private:
|
||||
template<typename Difference>
|
||||
static iter_type make_first(Rng& rng, Difference stride)
|
||||
{
|
||||
return make_strided_iterator(boost::begin(rng), stride);
|
||||
}
|
||||
|
||||
template<typename Difference>
|
||||
static iter_type make_last(Rng& rng, Difference stride)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Rng>::type raw_iter_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME range_difference<Rng>::type diff_t;
|
||||
|
||||
if (stride > 0)
|
||||
{
|
||||
raw_iter_t it = boost::end(rng);
|
||||
const diff_t count = boost::size(rng);
|
||||
std::advance(it, -(count % stride));
|
||||
return iter_type(it, stride);
|
||||
}
|
||||
return make_strided_iterator(boost::end(rng), stride);
|
||||
}
|
||||
};
|
||||
|
||||
@ -99,7 +121,7 @@ namespace boost
|
||||
class strided_holder : public holder<Difference>
|
||||
{
|
||||
public:
|
||||
strided_holder(Difference value) : holder<Difference>(value) {}
|
||||
explicit strided_holder(Difference value) : holder<Difference>(value) {}
|
||||
};
|
||||
|
||||
template<class Rng, class Difference>
|
||||
@ -117,32 +139,32 @@ namespace boost
|
||||
}
|
||||
|
||||
} // namespace range_detail
|
||||
|
||||
|
||||
using range_detail::strided_range;
|
||||
|
||||
namespace adaptors
|
||||
{
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
const range_detail::forwarder<range_detail::strided_holder>
|
||||
strided = range_detail::forwarder<range_detail::strided_holder>();
|
||||
}
|
||||
|
||||
|
||||
template<class Range, class Difference>
|
||||
inline strided_range<Range>
|
||||
stride(Range& rng, Difference step)
|
||||
{
|
||||
return strided_range<Range>(step, rng);
|
||||
}
|
||||
|
||||
|
||||
template<class Range, class Difference>
|
||||
inline strided_range<const Range>
|
||||
stride(const Range& rng, Difference step)
|
||||
{
|
||||
return strided_range<const Range>(step, rng);
|
||||
}
|
||||
|
||||
|
||||
} // namespace 'adaptors'
|
||||
} // namespace 'boost'
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <boost/range/adaptor/argument_fwd.hpp>
|
||||
#include <boost/range/iterator_range.hpp>
|
||||
#include <boost/iterator/transform_iterator.hpp>
|
||||
#include <boost/utility/result_of.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@ -21,17 +22,17 @@ namespace boost
|
||||
{
|
||||
|
||||
template< class F, class R >
|
||||
struct transform_range :
|
||||
public boost::iterator_range<
|
||||
struct transform_range :
|
||||
public boost::iterator_range<
|
||||
boost::transform_iterator< F,
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<R>::type
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<R>::type
|
||||
>
|
||||
>
|
||||
{
|
||||
private:
|
||||
typedef boost::iterator_range<
|
||||
typedef boost::iterator_range<
|
||||
boost::transform_iterator< F,
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<R>::type
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<R>::type
|
||||
>
|
||||
>
|
||||
base;
|
||||
@ -39,11 +40,11 @@ namespace boost
|
||||
public:
|
||||
typedef F transform_fn_type;
|
||||
typedef R source_range_type;
|
||||
|
||||
|
||||
transform_range( F f, R& r )
|
||||
: base( make_transform_iterator( boost::begin(r), f ),
|
||||
make_transform_iterator( boost::end(r), f ) )
|
||||
|
||||
make_transform_iterator( boost::end(r), f ) )
|
||||
|
||||
{ }
|
||||
};
|
||||
|
||||
@ -53,43 +54,43 @@ namespace boost
|
||||
transform_holder( T r ) : holder<T>(r)
|
||||
{ }
|
||||
};
|
||||
|
||||
|
||||
template< class InputRng, class UnaryFunction >
|
||||
inline transform_range<UnaryFunction,InputRng>
|
||||
operator|( InputRng& r,
|
||||
inline transform_range<UnaryFunction,InputRng>
|
||||
operator|( InputRng& r,
|
||||
const transform_holder<UnaryFunction>& f )
|
||||
{
|
||||
return transform_range<UnaryFunction,InputRng>( f.val, r );
|
||||
return transform_range<UnaryFunction,InputRng>( f.val, r );
|
||||
}
|
||||
|
||||
|
||||
template< class InputRng, class UnaryFunction >
|
||||
inline transform_range<UnaryFunction, const InputRng>
|
||||
operator|( const InputRng& r,
|
||||
inline transform_range<UnaryFunction, const InputRng>
|
||||
operator|( const InputRng& r,
|
||||
const transform_holder<UnaryFunction>& f )
|
||||
{
|
||||
return transform_range<UnaryFunction, const InputRng>( f.val, r );
|
||||
return transform_range<UnaryFunction, const InputRng>( f.val, r );
|
||||
}
|
||||
|
||||
|
||||
} // 'range_detail'
|
||||
|
||||
using range_detail::transform_range;
|
||||
|
||||
|
||||
namespace adaptors
|
||||
{
|
||||
{
|
||||
namespace
|
||||
{
|
||||
const range_detail::forwarder<range_detail::transform_holder>
|
||||
transformed =
|
||||
const range_detail::forwarder<range_detail::transform_holder>
|
||||
transformed =
|
||||
range_detail::forwarder<range_detail::transform_holder>();
|
||||
}
|
||||
|
||||
|
||||
template<class UnaryFunction, class InputRange>
|
||||
inline transform_range<UnaryFunction, InputRange>
|
||||
transform(InputRange& rng, UnaryFunction fn)
|
||||
{
|
||||
return transform_range<UnaryFunction, InputRange>(fn, rng);
|
||||
}
|
||||
|
||||
|
||||
template<class UnaryFunction, class InputRange>
|
||||
inline transform_range<UnaryFunction, const InputRange>
|
||||
transform(const InputRange& rng, UnaryFunction fn)
|
||||
@ -97,7 +98,7 @@ namespace boost
|
||||
return transform_range<UnaryFunction, const InputRange>(fn, rng);
|
||||
}
|
||||
} // 'adaptors'
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
90
include/boost/range/adaptor/type_erased.hpp
Normal file
90
include/boost/range/adaptor/type_erased.hpp
Normal file
@ -0,0 +1,90 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#ifndef BOOST_RANGE_ADAPTOR_TYPE_ERASED_HPP_INCLUDED
|
||||
#define BOOST_RANGE_ADAPTOR_TYPE_ERASED_HPP_INCLUDED
|
||||
|
||||
#include <boost/iterator/iterator_facade.hpp>
|
||||
#include <boost/range/range_reference.hpp>
|
||||
#include <boost/range/range_value.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace range_detail
|
||||
{
|
||||
template<
|
||||
class Value,
|
||||
class CategoryOrTraversal,
|
||||
class Reference,
|
||||
class Difference
|
||||
>
|
||||
class any_range
|
||||
: public iterator_range<
|
||||
IteratorTypeErasure::any_iterator<
|
||||
Value, CategoryOrTraversal, Reference, Difference> >
|
||||
{
|
||||
typedef typename IteratorTypeErasure::any_iterator<
|
||||
Value, CategoryOrTraversal, Reference, Difference> iterator_t;
|
||||
|
||||
typedef iterator_range<iterator_t> base_t;
|
||||
public:
|
||||
template<class Range>
|
||||
explicit any_range(Range& r) : base_t(r) {}
|
||||
|
||||
template<class Range>
|
||||
explicit any_range(const Range& r) : base_t(r) {}
|
||||
};
|
||||
|
||||
template<class Range>
|
||||
class any_range_generator
|
||||
{
|
||||
public:
|
||||
typedef any_range<
|
||||
BOOST_DEDUCED_TYPENAME range_value<Range>::type,
|
||||
BOOST_DEDUCED_TYPENAME iterator_traversal<
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Range>::type
|
||||
>::type,
|
||||
BOOST_DEDUCED_TYPENAME range_reference<Range>::type,
|
||||
BOOST_DEDUCED_TYPENAME range_difference<Range>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
class type_erased_tag {};
|
||||
|
||||
|
||||
} // namespace range_detail
|
||||
|
||||
using range_detail::any_range;
|
||||
|
||||
namespace adaptors
|
||||
{
|
||||
namespace
|
||||
{
|
||||
const range_detail::type_erased_tag type_erased = range_detail::type_erased_tag();
|
||||
}
|
||||
|
||||
template<class SinglePassRange>
|
||||
typename range_detail::any_range_generator<SinglePassRange>::type
|
||||
operator|(SinglePassRange& rng, range_detail::type_erased_tag)
|
||||
{
|
||||
typedef typename range_detail::any_range_generator<SinglePassRange>::type range_t;
|
||||
return range_t(rng);
|
||||
}
|
||||
|
||||
template<class SinglePassRange>
|
||||
typename range_detail::any_range_generator<const SinglePassRange>::type
|
||||
operator|(const SinglePassRange& rng, range_detail::type_erased_tag)
|
||||
{
|
||||
typedef typename range_detail::any_range_generator<const SinglePassRange>::type range_t;
|
||||
return range_t(rng);
|
||||
}
|
||||
}
|
||||
} // namespace boost
|
||||
|
||||
#endif // include guard
|
Reference in New Issue
Block a user