1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2014, Oracle and/or its affiliates.
5 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
7 // Licensed under the Boost Software License version 1.0.
8 // http://www.boost.org/users/license.html
10 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_CHECK_ITERATOR_RANGE_HPP
11 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_CHECK_ITERATOR_RANGE_HPP
13 #include <boost/core/ignore_unused.hpp>
16 namespace boost { namespace geometry
19 #ifndef DOXYGEN_NO_DETAIL
23 // Check whether (each element of) an iterator range satisfies a given
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
31 template <typename InputIterator>
32 static inline bool apply(InputIterator first, InputIterator beyond)
34 for (InputIterator it = first; it != beyond; ++it)
36 if (! Predicate::apply(*it))
41 return AllowEmptyRange || first != beyond;
45 // version where we can pass a predicate object
46 template <typename InputIterator>
47 static inline bool apply(InputIterator first,
49 Predicate const& predicate)
51 // in case predicate's apply method is static, MSVC will
52 // complain that predicate is not used
53 boost::ignore_unused(predicate);
55 for (InputIterator it = first; it != beyond; ++it)
57 if (! predicate.apply(*it))
62 return AllowEmptyRange || first != beyond;
67 #endif // DOXYGEN_NO_DETAIL
69 }} // namespace boost::geometry
71 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_CHECK_ITERATOR_RANGE_HPP