File indexing completed on 2025-01-18 09:51:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_RANGE_ADAPTOR_SLICED_HPP
0012 #define BOOST_RANGE_ADAPTOR_SLICED_HPP
0013
0014 #include <boost/range/adaptor/argument_fwd.hpp>
0015 #include <boost/range/size_type.hpp>
0016 #include <boost/range/iterator_range.hpp>
0017 #include <boost/range/concepts.hpp>
0018 #include <boost/next_prior.hpp>
0019
0020 namespace boost
0021 {
0022 namespace adaptors
0023 {
0024 struct sliced
0025 {
0026 sliced(std::size_t t_, std::size_t u_)
0027 : t(t_), u(u_) {}
0028 std::size_t t;
0029 std::size_t u;
0030 };
0031
0032 template< class RandomAccessRange >
0033 class sliced_range : public boost::iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<RandomAccessRange>::type >
0034 {
0035 typedef boost::iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<RandomAccessRange>::type > base_t;
0036 public:
0037 template<typename Rng, typename T, typename U>
0038 sliced_range(Rng& rng, T t, U u)
0039 : base_t(boost::next(boost::begin(rng), t),
0040 boost::next(boost::begin(rng), u))
0041 {
0042 }
0043 };
0044
0045 template< class RandomAccessRange >
0046 inline sliced_range<RandomAccessRange>
0047 slice( RandomAccessRange& rng, std::size_t t, std::size_t u )
0048 {
0049 BOOST_RANGE_CONCEPT_ASSERT((
0050 RandomAccessRangeConcept<RandomAccessRange>));
0051
0052 BOOST_ASSERT( t <= u && "error in slice indices" );
0053 BOOST_ASSERT( static_cast<std::size_t>(boost::size(rng)) >= u &&
0054 "second slice index out of bounds" );
0055
0056 return sliced_range<RandomAccessRange>(rng, t, u);
0057 }
0058
0059 template< class RandomAccessRange >
0060 inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<const RandomAccessRange>::type >
0061 slice( const RandomAccessRange& rng, std::size_t t, std::size_t u )
0062 {
0063 BOOST_RANGE_CONCEPT_ASSERT((
0064 RandomAccessRangeConcept<const RandomAccessRange>));
0065
0066 BOOST_ASSERT( t <= u && "error in slice indices" );
0067 BOOST_ASSERT( static_cast<std::size_t>(boost::size(rng)) >= u &&
0068 "second slice index out of bounds" );
0069
0070 return sliced_range<const RandomAccessRange>(rng, t, u);
0071 }
0072
0073 template< class RandomAccessRange >
0074 inline sliced_range<RandomAccessRange>
0075 operator|( RandomAccessRange& r, const sliced& f )
0076 {
0077 BOOST_RANGE_CONCEPT_ASSERT((
0078 RandomAccessRangeConcept<RandomAccessRange>));
0079
0080 return sliced_range<RandomAccessRange>( r, f.t, f.u );
0081 }
0082
0083 template< class RandomAccessRange >
0084 inline sliced_range<const RandomAccessRange>
0085 operator|( const RandomAccessRange& r, const sliced& f )
0086 {
0087 BOOST_RANGE_CONCEPT_ASSERT((
0088 RandomAccessRangeConcept<const RandomAccessRange>));
0089
0090 return sliced_range<const RandomAccessRange>( r, f.t, f.u );
0091 }
0092
0093 }
0094 using adaptors::sliced_range;
0095 }
0096
0097 #endif