/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_VIEW_REPLACE_HPP #define RANGES_V3_VIEW_REPLACE_HPP #include #include #include #include #include #include #include #include #include #include RANGES_DISABLE_WARNINGS namespace ranges { /// \cond namespace detail { template struct replacer_fn { private: Val1 old_value_; Val2 new_value_; public: replacer_fn() = default; constexpr replacer_fn(Val1 old_value, Val2 new_value) : old_value_(std::move(old_value)) , new_value_(std::move(new_value)) {} template [[noreturn]] common_type_t>, iter_value_t> & operator()(copy_tag, I const &) const { RANGES_EXPECT(false); } template common_reference_t, iter_reference_t> operator()(I const & i) const { auto && x = *i; if(x == unwrap_reference(old_value_)) return unwrap_reference(new_value_); return ((decltype(x) &&)x); } template common_reference_t, iter_rvalue_reference_t> operator()(move_tag, I const & i) const { auto && x = iter_move(i); if(x == unwrap_reference(old_value_)) return unwrap_reference(new_value_); return ((decltype(x) &&)x); } }; } // namespace detail /// \endcond /// \addtogroup group-views /// @{ namespace views { struct replace_fn { private: friend view_access; template static constexpr auto CPP_fun(bind)(replace_fn replace, Val1 old_value, Val2 new_value)( // requires same_as>, detail::decay_t>>) { return make_pipeable( bind_back(replace, std::move(old_value), std::move(new_value))); } public: template constexpr auto operator()( Rng && rng, Val1 && old_value, Val2 && new_value) const -> CPP_ret(replace_view, detail::decay_t, detail::decay_t>)( // requires viewable_range && input_range && same_as< detail::decay_t>, detail::decay_t>> && equality_comparable_with>, range_value_t> && common_with>, range_value_t> && common_reference_with, range_reference_t> && common_reference_with, range_rvalue_reference_t>) { return { all(static_cast(rng)), {static_cast(old_value), static_cast(new_value)}}; } }; /// \relates replace_fn /// \ingroup group-views RANGES_INLINE_VARIABLE(view, replace) } // namespace views /// @} } // namespace ranges RANGES_RE_ENABLE_WARNINGS #endif