Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:04:25

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_RANGE_SIZE_H
0012 #define BOOST_COMPUTE_DETAIL_ITERATOR_RANGE_SIZE_H
0013 
0014 #include <cstddef>
0015 #include <algorithm>
0016 #include <iterator>
0017 
0018 namespace boost {
0019 namespace compute {
0020 namespace detail {
0021 
0022 // This is a convenience function which returns the size of a range
0023 // bounded by two iterators. This function has two differences from
0024 // the std::distance() function: 1) the return type (size_t) is
0025 // unsigned, and 2) the return value is always positive.
0026 template<class Iterator>
0027 inline size_t iterator_range_size(Iterator first, Iterator last)
0028 {
0029     typedef typename
0030         std::iterator_traits<Iterator>::difference_type
0031         difference_type;
0032 
0033     difference_type difference = std::distance(first, last);
0034 
0035     return static_cast<size_t>(
0036         (std::max)(difference, static_cast<difference_type>(0))
0037     );
0038 }
0039 
0040 } // end detail namespace
0041 } // end compute namespace
0042 } // end boost namespace
0043 
0044 #endif // BOOST_COMPUTE_DETAIL_ITERATOR_RANGE_SIZE_H