1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
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
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #ifndef BOOST_COMPUTE_DETAIL_ITERATOR_RANGE_SIZE_H
12 #define BOOST_COMPUTE_DETAIL_ITERATOR_RANGE_SIZE_H
22 // This is a convenience function which returns the size of a range
23 // bounded by two iterators. This function has two differences from
24 // the std::distance() function: 1) the return type (size_t) is
25 // unsigned, and 2) the return value is always positive.
26 template<class Iterator>
27 inline size_t iterator_range_size(Iterator first, Iterator last)
30 std::iterator_traits<Iterator>::difference_type
33 difference_type difference = std::distance(first, last);
35 return static_cast<size_t>(
36 (std::max)(difference, static_cast<difference_type>(0))
40 } // end detail namespace
41 } // end compute namespace
42 } // end boost namespace
44 #endif // BOOST_COMPUTE_DETAIL_ITERATOR_RANGE_SIZE_H