nth_element.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #ifndef BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_NTH_ELEMENT_HPP
  9. #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_NTH_ELEMENT_HPP
  10. #include <algorithm>
  11. namespace boost { namespace geometry { namespace index { namespace detail {
  12. // See https://svn.boost.org/trac/boost/ticket/12861
  13. // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58800
  14. // https://gcc.gnu.org/develop.html#timeline
  15. // 20120920 4.7.2 - no bug
  16. // 20130322 4.8.0 - no bug
  17. // 20130411 4.7.3 - no bug
  18. // 20130531 4.8.1 - no bug
  19. // 20131016 4.8.2 - bug
  20. // 20140422 4.9.0 - fixed
  21. // 20140522 4.8.3 - fixed
  22. // 20140612 4.7.4 - fixed
  23. // 20140716 4.9.1 - fixed
  24. #if defined(__GLIBCXX__) && (__GLIBCXX__ == 20131016)
  25. #warning "std::nth_element replaced with std::sort, libstdc++ bug workaround.";
  26. template <typename RandomIt>
  27. void nth_element(RandomIt first, RandomIt , RandomIt last)
  28. {
  29. std::sort(first, last);
  30. }
  31. template <typename RandomIt, typename Compare>
  32. void nth_element(RandomIt first, RandomIt , RandomIt last, Compare comp)
  33. {
  34. std::sort(first, last, comp);
  35. }
  36. #else
  37. template <typename RandomIt>
  38. void nth_element(RandomIt first, RandomIt nth, RandomIt last)
  39. {
  40. std::nth_element(first, nth, last);
  41. }
  42. template <typename RandomIt, typename Compare>
  43. void nth_element(RandomIt first, RandomIt nth, RandomIt last, Compare comp)
  44. {
  45. std::nth_element(first, nth, last, comp);
  46. }
  47. #endif
  48. }}}} // namespace boost::geometry::index::detail
  49. #endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_NTH_ELEMENT_HPP