Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:27:53

0001 /// \file
0002 // Range v3 library
0003 //
0004 //  Copyright Eric Niebler 2014-present
0005 //
0006 //  Use, modification and distribution is subject to the
0007 //  Boost Software License, Version 1.0. (See accompanying
0008 //  file LICENSE_1_0.txt or copy at
0009 //  http://www.boost.org/LICENSE_1_0.txt)
0010 //
0011 // Project home: https://github.com/ericniebler/range-v3
0012 //
0013 #ifndef RANGES_V3_ALGORITHM_COUNT_IF_HPP
0014 #define RANGES_V3_ALGORITHM_COUNT_IF_HPP
0015 
0016 #include <utility>
0017 
0018 #include <range/v3/range_fwd.hpp>
0019 
0020 #include <range/v3/functional/identity.hpp>
0021 #include <range/v3/functional/invoke.hpp>
0022 #include <range/v3/iterator/concepts.hpp>
0023 #include <range/v3/iterator/traits.hpp>
0024 #include <range/v3/range/access.hpp>
0025 #include <range/v3/range/concepts.hpp>
0026 #include <range/v3/range/traits.hpp>
0027 #include <range/v3/utility/static_const.hpp>
0028 
0029 #include <range/v3/detail/prologue.hpp>
0030 
0031 namespace ranges
0032 {
0033     /// \addtogroup group-algorithms
0034     /// @{
0035     RANGES_FUNC_BEGIN(count_if)
0036 
0037         /// \brief function template \c count_if
0038         template(typename I, typename S, typename R, typename P = identity)(
0039             requires input_iterator<I> AND sentinel_for<S, I> AND
0040             indirect_unary_predicate<R, projected<I, P>>)
0041         constexpr iter_difference_t<I> RANGES_FUNC(count_if)(I first, S last, R pred, P proj = P{})
0042         {
0043             iter_difference_t<I> n = 0;
0044             for(; first != last; ++first)
0045                 if(invoke(pred, invoke(proj, *first)))
0046                     ++n;
0047             return n;
0048         }
0049 
0050         /// \overload
0051         template(typename Rng, typename R, typename P = identity)(
0052             requires input_range<Rng> AND
0053             indirect_unary_predicate<R, projected<iterator_t<Rng>, P>>)
0054         constexpr iter_difference_t<iterator_t<Rng>> //
0055         RANGES_FUNC(count_if)(Rng && rng, R pred, P proj = P{})
0056         {
0057             return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
0058         }
0059 
0060     RANGES_FUNC_END(count_if)
0061 
0062     namespace cpp20
0063     {
0064         using ranges::count_if;
0065     }
0066     /// @}
0067 } // namespace ranges
0068 
0069 #include <range/v3/detail/epilogue.hpp>
0070 
0071 #endif