Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:09:42

0001 /// \file
0002 // Range v3 library
0003 //
0004 //  Copyright Eric Niebler 2013-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 
0014 #ifndef RANGES_V3_ACTION_REMOVE_IF_HPP
0015 #define RANGES_V3_ACTION_REMOVE_IF_HPP
0016 
0017 #include <utility>
0018 
0019 #include <range/v3/range_fwd.hpp>
0020 
0021 #include <range/v3/action/action.hpp>
0022 #include <range/v3/action/erase.hpp>
0023 #include <range/v3/algorithm/remove_if.hpp>
0024 #include <range/v3/functional/bind_back.hpp>
0025 #include <range/v3/functional/identity.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     // TODO Look at all the special cases handled by erase_if in Library Fundamentals 2
0034 
0035     /// \addtogroup group-actions
0036     /// @{
0037     namespace actions
0038     {
0039         struct remove_if_fn
0040         {
0041             template(typename C, typename P = identity)(
0042                 requires (!range<C>))
0043             constexpr auto operator()(C pred, P proj = P{}) const
0044             {
0045                 return make_action_closure(
0046                     bind_back(remove_if_fn{}, std::move(pred), std::move(proj)));
0047             }
0048 
0049             template(typename Rng, typename C, typename P = identity)(
0050                 requires forward_range<Rng> AND
0051                     erasable_range<Rng &, iterator_t<Rng>, iterator_t<Rng>> AND
0052                         permutable<iterator_t<Rng>> AND
0053                             indirect_unary_predicate<C, projected<iterator_t<Rng>, P>>)
0054             Rng operator()(Rng && rng, C pred, P proj = P{}) const
0055             {
0056                 auto it = ranges::remove_if(rng, std::move(pred), std::move(proj));
0057                 ranges::erase(rng, it, ranges::end(rng));
0058                 return static_cast<Rng &&>(rng);
0059             }
0060         };
0061 
0062         /// \relates actions::remove_if_fn
0063         RANGES_INLINE_VARIABLE(remove_if_fn, remove_if)
0064     } // namespace actions
0065     /// @}
0066 } // namespace ranges
0067 
0068 #include <range/v3/detail/epilogue.hpp>
0069 
0070 #endif