1 // Copyright Neil Groves 2009. Use, modification and
2 // distribution is subject to the Boost Software License, Version
3 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
7 // For more information, see http://www.boost.org/libs/range/
9 #ifndef BOOST_RANGE_ALGORITHM_NTH_ELEMENT_HPP_INCLUDED
10 #define BOOST_RANGE_ALGORITHM_NTH_ELEMENT_HPP_INCLUDED
12 #include <boost/concept_check.hpp>
13 #include <boost/range/begin.hpp>
14 #include <boost/range/end.hpp>
15 #include <boost/range/concepts.hpp>
23 /// \brief template function nth_element
25 /// range-based version of the nth_element std algorithm
27 /// \pre RandomAccessRange is a model of the RandomAccessRangeConcept
28 /// \pre BinaryPredicate is a model of the BinaryPredicateConcept
29 template<class RandomAccessRange>
30 inline RandomAccessRange& nth_element(RandomAccessRange& rng,
31 BOOST_DEDUCED_TYPENAME range_iterator<RandomAccessRange>::type nth)
33 BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<RandomAccessRange> ));
34 std::nth_element(boost::begin(rng), nth, boost::end(rng));
39 template<class RandomAccessRange>
40 inline const RandomAccessRange& nth_element(const RandomAccessRange& rng,
41 BOOST_DEDUCED_TYPENAME range_iterator<const RandomAccessRange>::type nth)
43 BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<const RandomAccessRange> ));
44 std::nth_element(boost::begin(rng), nth, boost::end(rng));
49 template<class RandomAccessRange, class BinaryPredicate>
50 inline RandomAccessRange& nth_element(RandomAccessRange& rng,
51 BOOST_DEDUCED_TYPENAME range_iterator<RandomAccessRange>::type nth,
52 BinaryPredicate sort_pred)
54 BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<RandomAccessRange> ));
55 std::nth_element(boost::begin(rng), nth, boost::end(rng), sort_pred);
60 template<class RandomAccessRange, class BinaryPredicate>
61 inline const RandomAccessRange& nth_element(const RandomAccessRange& rng,
62 BOOST_DEDUCED_TYPENAME range_iterator<const RandomAccessRange>::type nth,
63 BinaryPredicate sort_pred)
65 BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<const RandomAccessRange> ));
66 std::nth_element(boost::begin(rng), nth, boost::end(rng), sort_pred);
71 using range::nth_element;
74 #endif // include guard