2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
2019-01-07 08:47:17 +00:00
|
|
|
Copyright (c) 2011-2019 Bolero MURAKAMI
|
2013-08-08 09:54:33 +00:00
|
|
|
https://github.com/bolero-MURAKAMI/Sprout
|
|
|
|
|
|
|
|
Distributed under 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)
|
|
|
|
=============================================================================*/
|
2013-02-01 11:21:01 +00:00
|
|
|
#ifndef SPROUT_ITERATOR_REPLACE_IF_ITERATOR_HPP
|
|
|
|
#define SPROUT_ITERATOR_REPLACE_IF_ITERATOR_HPP
|
2013-01-16 18:53:17 +00:00
|
|
|
|
|
|
|
#include <sprout/config.hpp>
|
|
|
|
#include <sprout/iterator/transform_iterator.hpp>
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
//
|
|
|
|
// replace_value_if
|
|
|
|
//
|
|
|
|
template<typename Predicate, typename T>
|
|
|
|
class replace_value_if {
|
|
|
|
public:
|
|
|
|
typedef Predicate predicate_type;
|
2013-01-19 23:53:20 +00:00
|
|
|
typedef T result_type;
|
2013-02-01 11:21:01 +00:00
|
|
|
typedef T argument_type;
|
2013-01-16 18:53:17 +00:00
|
|
|
private:
|
|
|
|
Predicate pred_;
|
|
|
|
T new_;
|
|
|
|
public:
|
|
|
|
SPROUT_CONSTEXPR replace_value_if(Predicate pred, T const& new_value)
|
2013-02-07 16:14:42 +00:00
|
|
|
: pred_(pred), new_(new_value)
|
2013-01-16 18:53:17 +00:00
|
|
|
{}
|
|
|
|
SPROUT_CONSTEXPR T operator()(T const& value) const {
|
|
|
|
return pred_(value) ? new_ : value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// make_replace_if_iterator
|
|
|
|
//
|
|
|
|
template<typename Predicate, typename T, typename Iterator>
|
|
|
|
inline SPROUT_CONSTEXPR sprout::transform_iterator<sprout::replace_value_if<Predicate, T>, Iterator>
|
|
|
|
make_replace_if_iterator(Iterator it, Predicate pred, T const& new_value) {
|
|
|
|
return sprout::transform_iterator<sprout::replace_value_if<Predicate, T>, Iterator>(
|
|
|
|
it, sprout::replace_value_if<Predicate, T>(pred, new_value)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} // namespace sprout
|
|
|
|
|
2013-02-01 11:21:01 +00:00
|
|
|
#endif // #ifndef SPROUT_ITERATOR_REPLACE_IF_ITERATOR_HPP
|