1 // Boost.Geometry Index
2 //
3 // Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland.
4 //
5 // Use, modification and distribution is subject to the Boost Software License,
6 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 
9 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_NTH_ELEMENT_HPP
10 #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_NTH_ELEMENT_HPP
11 
12 #include <algorithm>
13 
14 namespace boost { namespace geometry { namespace index { namespace detail {
15 
16 // See https://svn.boost.org/trac/boost/ticket/12861
17 //     https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58800
18 //     https://gcc.gnu.org/develop.html#timeline
19 // 20120920 4.7.2 - no bug
20 // 20130322 4.8.0 - no bug
21 // 20130411 4.7.3 - no bug
22 // 20130531 4.8.1 - no bug
23 // 20131016 4.8.2 - bug
24 // 20140422 4.9.0 - fixed
25 // 20140522 4.8.3 - fixed
26 // 20140612 4.7.4 - fixed
27 // 20140716 4.9.1 - fixed
28 #if defined(__GLIBCXX__) && (__GLIBCXX__ == 20131016)
29 
30 #warning "std::nth_element replaced with std::sort, libstdc++ bug workaround.";
31 
32 template <typename RandomIt>
nth_element(RandomIt first,RandomIt,RandomIt last)33 void nth_element(RandomIt first, RandomIt , RandomIt last)
34 {
35     std::sort(first, last);
36 }
37 
38 template <typename RandomIt, typename Compare>
nth_element(RandomIt first,RandomIt,RandomIt last,Compare comp)39 void nth_element(RandomIt first, RandomIt , RandomIt last, Compare comp)
40 {
41     std::sort(first, last, comp);
42 }
43 
44 #else
45 
46 template <typename RandomIt>
47 void nth_element(RandomIt first, RandomIt nth, RandomIt last)
48 {
49     std::nth_element(first, nth, last);
50 }
51 
52 template <typename RandomIt, typename Compare>
53 void nth_element(RandomIt first, RandomIt nth, RandomIt last, Compare comp)
54 {
55     std::nth_element(first, nth, last, comp);
56 }
57 
58 #endif
59 
60 }}}} // namespace boost::geometry::index::detail
61 
62 #endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_NTH_ELEMENT_HPP
63