Imported Upstream version 1.57.0
[platform/upstream/boost.git] / boost / geometry / algorithms / detail / is_valid / has_duplicates.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_IS_VALID_HAS_DUPLICATES_HPP
11 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_HAS_DUPLICATES_HPP
12
13 #include <boost/range.hpp>
14
15 #include <boost/geometry/core/closure.hpp>
16
17 #include <boost/geometry/policies/compare.hpp>
18
19 #include <boost/geometry/views/closeable_view.hpp>
20
21
22 namespace boost { namespace geometry
23 {
24
25
26 #ifndef DOXYGEN_NO_DETAIL
27 namespace detail { namespace is_valid
28 {
29
30 template <typename Range, closure_selector Closure>
31 struct has_duplicates
32 {
33     static inline bool apply(Range const& range)
34     {
35         typedef typename closeable_view<Range const, Closure>::type view_type;
36         typedef typename boost::range_iterator<view_type const>::type iterator;
37
38         view_type view(range);
39
40         if ( boost::size(view) < 2 )
41         {
42             return false;
43         }
44
45         geometry::equal_to<typename boost::range_value<Range>::type> equal;
46
47         iterator it = boost::begin(view);
48         iterator next = ++boost::begin(view);
49         for (; next != boost::end(view); ++it, ++next)
50         {
51             if ( equal(*it, *next) )
52             {
53                 return true;
54             }
55         }
56         return false;
57     }
58 };
59
60
61
62 }} // namespace detail::is_valid
63 #endif // DOXYGEN_NO_DETAIL
64
65
66 }} // namespace boost::geometry
67
68
69
70 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_HAS_DUPLICATES_HPP