annotate DEPENDENCIES/generic/include/boost/range/adaptor/sliced.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
rev   line source
Chris@16 1 // Boost.Range library
Chris@16 2 //
Chris@16 3 // Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. Use, modification and
Chris@16 4 // distribution is subject to the Boost Software License, Version
Chris@16 5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 6 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 7 //
Chris@16 8 // For more information, see http://www.boost.org/libs/range/
Chris@16 9 //
Chris@16 10
Chris@16 11 #ifndef BOOST_RANGE_ADAPTOR_SLICED_HPP
Chris@16 12 #define BOOST_RANGE_ADAPTOR_SLICED_HPP
Chris@16 13
Chris@16 14 #include <boost/range/adaptor/argument_fwd.hpp>
Chris@16 15 #include <boost/range/size_type.hpp>
Chris@16 16 #include <boost/range/iterator_range.hpp>
Chris@16 17
Chris@16 18 namespace boost
Chris@16 19 {
Chris@16 20 namespace adaptors
Chris@16 21 {
Chris@16 22 struct sliced
Chris@16 23 {
Chris@16 24 sliced(std::size_t t_, std::size_t u_)
Chris@16 25 : t(t_), u(u_) {}
Chris@16 26 std::size_t t;
Chris@16 27 std::size_t u;
Chris@16 28 };
Chris@16 29
Chris@16 30 template< class RandomAccessRange >
Chris@16 31 class sliced_range : public boost::iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<RandomAccessRange>::type >
Chris@16 32 {
Chris@16 33 typedef boost::iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<RandomAccessRange>::type > base_t;
Chris@16 34 public:
Chris@16 35 template<typename Rng, typename T, typename U>
Chris@16 36 sliced_range(Rng& rng, T t, U u)
Chris@16 37 : base_t(boost::make_iterator_range(rng, t, u - boost::size(rng)))
Chris@16 38 {
Chris@16 39 }
Chris@16 40 };
Chris@16 41
Chris@16 42 template< class RandomAccessRange >
Chris@16 43 inline sliced_range<RandomAccessRange>
Chris@16 44 slice( RandomAccessRange& rng, std::size_t t, std::size_t u )
Chris@16 45 {
Chris@16 46 BOOST_ASSERT( t <= u && "error in slice indices" );
Chris@16 47 BOOST_ASSERT( static_cast<std::size_t>(boost::size(rng)) >= u &&
Chris@16 48 "second slice index out of bounds" );
Chris@16 49
Chris@16 50 return sliced_range<RandomAccessRange>(rng, t, u);
Chris@16 51 }
Chris@16 52
Chris@16 53 template< class RandomAccessRange >
Chris@16 54 inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<const RandomAccessRange>::type >
Chris@16 55 slice( const RandomAccessRange& rng, std::size_t t, std::size_t u )
Chris@16 56 {
Chris@16 57 BOOST_ASSERT( t <= u && "error in slice indices" );
Chris@16 58 BOOST_ASSERT( static_cast<std::size_t>(boost::size(rng)) >= u &&
Chris@16 59 "second slice index out of bounds" );
Chris@16 60
Chris@16 61 return sliced_range<const RandomAccessRange>(rng, t, u);
Chris@16 62 }
Chris@16 63
Chris@16 64 template< class RandomAccessRange >
Chris@16 65 inline sliced_range<RandomAccessRange>
Chris@16 66 operator|( RandomAccessRange& r, const sliced& f )
Chris@16 67 {
Chris@16 68 return sliced_range<RandomAccessRange>( r, f.t, f.u );
Chris@16 69 }
Chris@16 70
Chris@16 71 template< class RandomAccessRange >
Chris@16 72 inline sliced_range<const RandomAccessRange>
Chris@16 73 operator|( const RandomAccessRange& r, const sliced& f )
Chris@16 74 {
Chris@16 75 return sliced_range<const RandomAccessRange>( r, f.t, f.u );
Chris@16 76 }
Chris@16 77
Chris@16 78 } // namespace adaptors
Chris@16 79 using adaptors::sliced_range;
Chris@16 80 } // namespace boost
Chris@16 81
Chris@16 82 #endif