]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/compute/include/boost/compute/detail/iterator_plus_distance.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / compute / include / boost / compute / detail / iterator_plus_distance.hpp
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
3 //
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7 //
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
10
11 #ifndef BOOST_COMPUTE_DETAIL_ITERATOR_PLUS_DISTANCE_HPP
12 #define BOOST_COMPUTE_DETAIL_ITERATOR_PLUS_DISTANCE_HPP
13
14 #include <iterator>
15
16 namespace boost {
17 namespace compute {
18 namespace detail {
19
20 template<class Iterator, class Distance, class Tag>
21 inline Iterator iterator_plus_distance(Iterator i, Distance n, Tag)
22 {
23 while(n--){ i++; }
24
25 return i;
26 }
27
28 template<class Iterator, class Distance>
29 inline Iterator iterator_plus_distance(Iterator i,
30 Distance n,
31 std::random_access_iterator_tag)
32 {
33 typedef typename
34 std::iterator_traits<Iterator>::difference_type difference_type;
35
36 return i + static_cast<difference_type>(n);
37 }
38
39 // similar to std::advance() except returns the advanced iterator and
40 // also works with iterators that don't define difference_type
41 template<class Iterator, class Distance>
42 inline Iterator iterator_plus_distance(Iterator i, Distance n)
43 {
44 typedef typename std::iterator_traits<Iterator>::iterator_category tag;
45
46 return iterator_plus_distance(i, n, tag());
47 }
48
49 } // end detail namespace
50 } // end compute namespace
51 } // end boost namespace
52
53 #endif // BOOST_COMPUTE_DETAIL_ITERATOR_PLUS_DISTANCE_HPP