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 | |
11 | #ifndef BOOST_RANGE_ADAPTOR_COPIED_HPP |
12 | #define BOOST_RANGE_ADAPTOR_COPIED_HPP |
13 | |
14 | #include <boost/range/adaptor/argument_fwd.hpp> |
15 | #include <boost/range/adaptor/sliced.hpp> |
16 | #include <boost/range/size_type.hpp> |
17 | #include <boost/range/iterator_range.hpp> |
18 | #include <boost/range/concepts.hpp> |
19 | |
20 | namespace boost |
21 | { |
22 | namespace adaptors |
23 | { |
24 | struct copied |
25 | { |
26 | copied(std::size_t t_, std::size_t u_) |
27 | : t(t_), u(u_) {} |
28 | |
29 | std::size_t t; |
30 | std::size_t u; |
31 | }; |
32 | |
33 | template<class CopyableRandomAccessRange> |
34 | inline CopyableRandomAccessRange |
35 | operator|(const CopyableRandomAccessRange& r, const copied& f) |
36 | { |
37 | BOOST_RANGE_CONCEPT_ASSERT(( |
38 | RandomAccessRangeConcept<const CopyableRandomAccessRange>)); |
39 | |
40 | iterator_range< |
41 | BOOST_DEDUCED_TYPENAME range_iterator< |
42 | const CopyableRandomAccessRange |
43 | >::type |
44 | > temp(adaptors::slice(r, f.t, f.u)); |
45 | |
46 | return CopyableRandomAccessRange(temp.begin(), temp.end()); |
47 | } |
48 | |
49 | template<class CopyableRandomAccessRange> |
50 | inline CopyableRandomAccessRange |
51 | copy(const CopyableRandomAccessRange& rng, std::size_t t, std::size_t u) |
52 | { |
53 | BOOST_RANGE_CONCEPT_ASSERT(( |
54 | RandomAccessRangeConcept<const CopyableRandomAccessRange>)); |
55 | |
56 | iterator_range< |
57 | BOOST_DEDUCED_TYPENAME range_iterator< |
58 | const CopyableRandomAccessRange |
59 | >::type |
60 | > temp(adaptors::slice(rng, t, u)); |
61 | |
62 | return CopyableRandomAccessRange( temp.begin(), temp.end() ); |
63 | } |
64 | } // 'adaptors' |
65 | |
66 | } |
67 | |
68 | #endif // include guard |
69 | |