14#ifndef CDT_PORTABLE_NTH_ELEMENT
15#define CDT_PORTABLE_NTH_ELEMENT
19#ifdef CDT_CXX11_IS_SUPPORTED
22#include <boost/type_traits/add_lvalue_reference.hpp>
34template <
class Compare,
class ForwardIterator>
36sort3(ForwardIterator x, ForwardIterator y, ForwardIterator z, Compare c)
70template <
class Compare,
class BirdirectionalIterator>
72 BirdirectionalIterator first,
73 BirdirectionalIterator last,
76 BirdirectionalIterator lm1 = last;
77 for(--lm1; first != lm1; ++first)
79#ifdef CDT_CXX11_IS_SUPPORTED
80 BirdirectionalIterator i = std::min_element<
81 BirdirectionalIterator,
82 typename std::add_lvalue_reference<Compare>::type>(
85 BirdirectionalIterator i = std::min_element<
86 BirdirectionalIterator,
87 typename boost::add_lvalue_reference<Compare>::type>(
91 std::swap(*first, *i);
97template <
class Compare,
class RandomAccessIterator>
99 RandomAccessIterator first,
100 RandomAccessIterator nth,
101 RandomAccessIterator last,
105 typedef typename std::iterator_traits<RandomAccessIterator>::difference_type
107 const difference_type limit = 7;
113 difference_type len = last - first;
120 if(comp(*--last, *first))
121 std::swap(*first, *last);
124 RandomAccessIterator m = first;
125 detail::sort3<Compare>(first, ++m, --last, comp);
131 detail::selection_sort<Compare>(first, last, comp);
135 RandomAccessIterator m = first + len / 2;
136 RandomAccessIterator lm1 = last;
137 unsigned n_swaps = detail::sort3<Compare>(first, m, --lm1, comp);
142 RandomAccessIterator i = first;
143 RandomAccessIterator j = lm1;
160 if(!comp(*first, *--j))
184 while(!comp(*first, *i))
186 while(comp(*first, *--j))
225 while(!comp(*--j, *m))
239 if(i != m && comp(*m, *i))
294template <
class _RandomAccessIterator,
class _Compare>
295inline void portable_nth_element(
296 _RandomAccessIterator first,
297 _RandomAccessIterator nth,
298 _RandomAccessIterator last,
301#ifdef CDT_CXX11_IS_SUPPORTED
302 detail::nth_element<typename std::add_lvalue_reference<_Compare>::type>(
303 first, nth, last, comp);
305 detail::nth_element<typename boost::add_lvalue_reference<_Compare>::type>(
306 first, nth, last, comp);
Namespace containing triangulation functionality.