]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/include/boost/geometry/algorithms/detail/check_iterator_range.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / geometry / include / boost / geometry / algorithms / detail / check_iterator_range.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2014, Oracle and/or its affiliates.
4
5 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
6
7 // Licensed under the Boost Software License version 1.0.
8 // http://www.boost.org/users/license.html
9
10 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_CHECK_ITERATOR_RANGE_HPP
11 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_CHECK_ITERATOR_RANGE_HPP
12
13 #include <boost/core/ignore_unused.hpp>
14
15
16 namespace boost { namespace geometry
17 {
18
19 #ifndef DOXYGEN_NO_DETAIL
20 namespace detail
21 {
22
23 // Check whether (each element of) an iterator range satisfies a given
24 // predicate.
25 // The predicate must be implemented as having a static apply unary
26 // method that returns a bool.
27 // By default an empty range is accepted
28 template <typename Predicate, bool AllowEmptyRange = true>
29 struct check_iterator_range
30 {
31 template <typename InputIterator>
32 static inline bool apply(InputIterator first, InputIterator beyond)
33 {
34 for (InputIterator it = first; it != beyond; ++it)
35 {
36 if (! Predicate::apply(*it))
37 {
38 return false;
39 }
40 }
41 return AllowEmptyRange || first != beyond;
42 }
43
44
45 // version where we can pass a predicate object
46 template <typename InputIterator>
47 static inline bool apply(InputIterator first,
48 InputIterator beyond,
49 Predicate const& predicate)
50 {
51 // in case predicate's apply method is static, MSVC will
52 // complain that predicate is not used
53 boost::ignore_unused(predicate);
54
55 for (InputIterator it = first; it != beyond; ++it)
56 {
57 if (! predicate.apply(*it))
58 {
59 return false;
60 }
61 }
62 return AllowEmptyRange || first != beyond;
63 }
64 };
65
66 } // namespace detail
67 #endif // DOXYGEN_NO_DETAIL
68
69 }} // namespace boost::geometry
70
71 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_CHECK_ITERATOR_RANGE_HPP