PageRenderTime 32ms CodeModel.GetById 11ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/range/algorithm/max_element.hpp

http://hadesmem.googlecode.com/
C++ Header | 115 lines | 80 code | 13 blank | 22 comment | 0 complexity | 72967e2f0dc446b46f0cb370aa314e29 MD5 | raw file
  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)
  5//
  6//
  7// For more information, see http://www.boost.org/libs/range/
  8//
  9#ifndef BOOST_RANGE_ALGORITHM_MAX_ELEMENT_HPP_INCLUDED
 10#define BOOST_RANGE_ALGORITHM_MAX_ELEMENT_HPP_INCLUDED
 11
 12#include <boost/concept_check.hpp>
 13#include <boost/range/begin.hpp>
 14#include <boost/range/end.hpp>
 15#include <boost/range/concepts.hpp>
 16#include <boost/range/detail/range_return.hpp>
 17#include <algorithm>
 18
 19namespace boost
 20{
 21    namespace range
 22    {
 23
 24/// \brief template function max_element
 25///
 26/// range-based version of the max_element std algorithm
 27///
 28/// \pre ForwardRange is a model of the ForwardRangeConcept
 29/// \pre BinaryPredicate is a model of the BinaryPredicateConcept
 30template<class ForwardRange>
 31inline BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
 32max_element(ForwardRange& rng)
 33{
 34    BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
 35    return std::max_element(boost::begin(rng), boost::end(rng));
 36}
 37
 38/// \overload
 39template<class ForwardRange>
 40inline BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type
 41max_element(const ForwardRange& rng)
 42{
 43    BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
 44    return std::max_element(boost::begin(rng), boost::end(rng));
 45}
 46
 47/// \overload
 48template<class ForwardRange, class BinaryPredicate>
 49inline BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
 50max_element(ForwardRange& rng, BinaryPredicate pred)
 51{
 52    BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
 53    return std::max_element(boost::begin(rng), boost::end(rng), pred);
 54}
 55
 56/// \overload
 57template<class ForwardRange, class BinaryPredicate>
 58inline BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type
 59max_element(const ForwardRange& rng, BinaryPredicate pred)
 60{
 61    BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
 62    return std::max_element(boost::begin(rng), boost::end(rng), pred);
 63}
 64
 65// range_return overloads
 66
 67/// \overload
 68template<range_return_value re, class ForwardRange>
 69inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type
 70max_element(ForwardRange& rng)
 71{
 72    BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
 73    return range_return<ForwardRange,re>::pack(
 74        std::max_element(boost::begin(rng), boost::end(rng)),
 75        rng);
 76}
 77
 78/// \overload
 79template<range_return_value re, class ForwardRange>
 80inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
 81max_element(const ForwardRange& rng)
 82{
 83    BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
 84    return range_return<const ForwardRange,re>::pack(
 85        std::max_element(boost::begin(rng), boost::end(rng)),
 86        rng);
 87}
 88
 89/// \overload
 90template<range_return_value re, class ForwardRange, class BinaryPredicate>
 91inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type
 92max_element(ForwardRange& rng, BinaryPredicate pred)
 93{
 94    BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
 95    return range_return<ForwardRange,re>::pack(
 96        std::max_element(boost::begin(rng), boost::end(rng), pred),
 97        rng);
 98}
 99
100/// \overload
101template<range_return_value re, class ForwardRange, class BinaryPredicate>
102inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
103max_element(const ForwardRange& rng, BinaryPredicate pred)
104{
105    BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
106    return range_return<const ForwardRange,re>::pack(
107        std::max_element(boost::begin(rng), boost::end(rng), pred),
108        rng);
109}
110
111    } // namespace range
112    using range::max_element;
113} // namespace boost
114
115#endif // include guard