copied.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Boost.Range library
  2. //
  3. // Copyright Thorsten Ottosen, Neil Groves 2006. Use, modification and
  4. // distribution is subject to the Boost Software License, Version
  5. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // For more information, see http://www.boost.org/libs/range/
  9. //
  10. #ifndef BOOST_RANGE_ADAPTOR_COPIED_HPP
  11. #define BOOST_RANGE_ADAPTOR_COPIED_HPP
  12. #include <boost/range/adaptor/argument_fwd.hpp>
  13. #include <boost/range/adaptor/sliced.hpp>
  14. #include <boost/range/size_type.hpp>
  15. #include <boost/range/iterator_range.hpp>
  16. #include <boost/range/concepts.hpp>
  17. namespace boost
  18. {
  19. namespace adaptors
  20. {
  21. struct copied
  22. {
  23. copied(std::size_t t_, std::size_t u_)
  24. : t(t_), u(u_) {}
  25. std::size_t t;
  26. std::size_t u;
  27. };
  28. template<class CopyableRandomAccessRange>
  29. inline CopyableRandomAccessRange
  30. operator|(const CopyableRandomAccessRange& r, const copied& f)
  31. {
  32. BOOST_RANGE_CONCEPT_ASSERT((
  33. RandomAccessRangeConcept<const CopyableRandomAccessRange>));
  34. iterator_range<
  35. BOOST_DEDUCED_TYPENAME range_iterator<
  36. const CopyableRandomAccessRange
  37. >::type
  38. > temp(adaptors::slice(r, f.t, f.u));
  39. return CopyableRandomAccessRange(temp.begin(), temp.end());
  40. }
  41. template<class CopyableRandomAccessRange>
  42. inline CopyableRandomAccessRange
  43. copy(const CopyableRandomAccessRange& rng, std::size_t t, std::size_t u)
  44. {
  45. BOOST_RANGE_CONCEPT_ASSERT((
  46. RandomAccessRangeConcept<const CopyableRandomAccessRange>));
  47. iterator_range<
  48. BOOST_DEDUCED_TYPENAME range_iterator<
  49. const CopyableRandomAccessRange
  50. >::type
  51. > temp(adaptors::slice(rng, t, u));
  52. return CopyableRandomAccessRange( temp.begin(), temp.end() );
  53. }
  54. } // 'adaptors'
  55. }
  56. #endif // include guard