]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/compute/include/boost/compute/detail/iterator_range_size.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / compute / include / boost / compute / detail / iterator_range_size.hpp
CommitLineData
7c673cae
FG
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_RANGE_SIZE_H
12#define BOOST_COMPUTE_DETAIL_ITERATOR_RANGE_SIZE_H
13
14#include <cstddef>
15#include <algorithm>
16#include <iterator>
17
18namespace boost {
19namespace compute {
20namespace detail {
21
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.
26template<class Iterator>
27inline size_t iterator_range_size(Iterator first, Iterator last)
28{
29 typedef typename
30 std::iterator_traits<Iterator>::difference_type
31 difference_type;
32
33 difference_type difference = std::distance(first, last);
34
35 return static_cast<size_t>(
36 (std::max)(difference, static_cast<difference_type>(0))
37 );
38}
39
40} // end detail namespace
41} // end compute namespace
42} // end boost namespace
43
44#endif // BOOST_COMPUTE_DETAIL_ITERATOR_RANGE_SIZE_H