Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:44:34

0001 //---------------------------------------------------------------------------//
0002 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 // See http://boostorg.github.com/compute for more information.
0009 //---------------------------------------------------------------------------//
0010 
0011 #ifndef BOOST_COMPUTE_DETAIL_ITERATOR_PLUS_DISTANCE_HPP
0012 #define BOOST_COMPUTE_DETAIL_ITERATOR_PLUS_DISTANCE_HPP
0013 
0014 #include <iterator>
0015 
0016 namespace boost {
0017 namespace compute {
0018 namespace detail {
0019 
0020 template<class Iterator, class Distance, class Tag>
0021 inline Iterator iterator_plus_distance(Iterator i, Distance n, Tag)
0022 {
0023     while(n--){ i++; }
0024 
0025     return i;
0026 }
0027 
0028 template<class Iterator, class Distance>
0029 inline Iterator iterator_plus_distance(Iterator i,
0030                                        Distance n,
0031                                        std::random_access_iterator_tag)
0032 {
0033     typedef typename
0034         std::iterator_traits<Iterator>::difference_type difference_type;
0035 
0036     return i + static_cast<difference_type>(n);
0037 }
0038 
0039 // similar to std::advance() except returns the advanced iterator and
0040 // also works with iterators that don't define difference_type
0041 template<class Iterator, class Distance>
0042 inline Iterator iterator_plus_distance(Iterator i, Distance n)
0043 {
0044     typedef typename std::iterator_traits<Iterator>::iterator_category tag;
0045 
0046     return iterator_plus_distance(i, n, tag());
0047 }
0048 
0049 } // end detail namespace
0050 } // end compute namespace
0051 } // end boost namespace
0052 
0053 #endif // BOOST_COMPUTE_DETAIL_ITERATOR_PLUS_DISTANCE_HPP