Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:59:16

0001 //  Copyright Neil Groves 2009. Use, modification and
0002 //  distribution is subject to the Boost Software License, Version
0003 //  1.0. (See accompanying file LICENSE_1_0.txt or copy at
0004 //  http://www.boost.org/LICENSE_1_0.txt)
0005 //
0006 //
0007 // For more information, see http://www.boost.org/libs/range/
0008 //
0009 #ifndef BOOST_RANGE_ALGORITHM_NTH_ELEMENT_HPP_INCLUDED
0010 #define BOOST_RANGE_ALGORITHM_NTH_ELEMENT_HPP_INCLUDED
0011 
0012 #include <boost/concept_check.hpp>
0013 #include <boost/range/begin.hpp>
0014 #include <boost/range/end.hpp>
0015 #include <boost/range/concepts.hpp>
0016 #include <algorithm>
0017 
0018 namespace boost
0019 {
0020     namespace range
0021     {
0022 
0023 /// \brief template function nth_element
0024 ///
0025 /// range-based version of the nth_element std algorithm
0026 ///
0027 /// \pre RandomAccessRange is a model of the RandomAccessRangeConcept
0028 /// \pre BinaryPredicate is a model of the BinaryPredicateConcept
0029 template<class RandomAccessRange>
0030 inline RandomAccessRange& nth_element(RandomAccessRange& rng,
0031     BOOST_DEDUCED_TYPENAME range_iterator<RandomAccessRange>::type nth)
0032 {
0033     BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<RandomAccessRange> ));
0034     std::nth_element(boost::begin(rng), nth, boost::end(rng));
0035     return rng;
0036 }
0037 
0038 /// \overload
0039 template<class RandomAccessRange>
0040 inline const RandomAccessRange& nth_element(const RandomAccessRange& rng,
0041     BOOST_DEDUCED_TYPENAME range_iterator<const RandomAccessRange>::type nth)
0042 {
0043     BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<const RandomAccessRange> ));
0044     std::nth_element(boost::begin(rng), nth, boost::end(rng));
0045     return rng;
0046 }
0047 
0048 /// \overload
0049 template<class RandomAccessRange, class BinaryPredicate>
0050 inline RandomAccessRange& nth_element(RandomAccessRange& rng,
0051     BOOST_DEDUCED_TYPENAME range_iterator<RandomAccessRange>::type nth,
0052     BinaryPredicate sort_pred)
0053 {
0054     BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<RandomAccessRange> ));
0055     std::nth_element(boost::begin(rng), nth, boost::end(rng), sort_pred);
0056     return rng;
0057 }
0058 
0059 /// \overload
0060 template<class RandomAccessRange, class BinaryPredicate>
0061 inline const RandomAccessRange& nth_element(const RandomAccessRange& rng,
0062     BOOST_DEDUCED_TYPENAME range_iterator<const RandomAccessRange>::type nth,
0063     BinaryPredicate sort_pred)
0064 {
0065     BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<const RandomAccessRange> ));
0066     std::nth_element(boost::begin(rng), nth, boost::end(rng), sort_pred);
0067     return rng;
0068 }
0069 
0070     } // namespace range
0071     using range::nth_element;
0072 } // namespace boost
0073 
0074 #endif // include guard