replace.hpp
Go to the documentation of this file.
00001 /* 00002 Copyright 2005-2007 Adobe Systems Incorporated 00003 Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt 00004 or a copy at http://stlab.adobe.com/licenses.html) 00005 */ 00006 00007 /*************************************************************************************************/ 00008 00009 #ifndef ADOBE_ALGORITHM_REPLACE_HPP 00010 #define ADOBE_ALGORITHM_REPLACE_HPP 00011 00012 #include <adobe/config.hpp> 00013 00014 #include <boost/range/begin.hpp> 00015 #include <boost/range/end.hpp> 00016 #include <boost/bind.hpp> 00017 00018 #include <algorithm> 00019 00020 /*************************************************************************************************/ 00021 00022 namespace adobe { 00023 00024 /*************************************************************************************************/ 00035 /*************************************************************************************************/ 00041 template <class ForwardRange, class T> 00042 inline void replace(ForwardRange& range, const T& old_value, const T& new_value) 00043 { 00044 std::replace(boost::begin(range), boost::end(range), old_value, new_value); 00045 } 00046 00052 template <class ForwardIterator, class Predicate, class T> 00053 inline void 00054 replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value) 00055 { 00056 std::replace_if(first, last, boost::bind(pred, _1), new_value); 00057 } 00058 00064 template <class ForwardRange, class Predicate, class T> 00065 inline void replace_if(ForwardRange& range, Predicate pred, const T& new_value) 00066 { 00067 adobe::replace_if(boost::begin(range), boost::end(range), pred, new_value); 00068 } 00069 00075 template <class ForwardRange, class OutputIterator, class T> 00076 inline OutputIterator 00077 replace_copy(ForwardRange& range, OutputIterator result, const T& old_value, const T& new_value) 00078 { 00079 return std::replace_copy(boost::begin(range), boost::end(range), result, old_value, new_value); 00080 } 00081 00087 template <class ForwardRange, class OutputIterator, class T> 00088 inline OutputIterator 00089 replace_copy(const ForwardRange& range, OutputIterator result, 00090 const T& old_value, const T& new_value) 00091 { 00092 return std::replace_copy(boost::begin(range), boost::end(range), result, old_value, new_value); 00093 } 00094 00100 template <class ForwardIterator, class OutputIterator, class Predicate, class T> 00101 inline OutputIterator 00102 replace_copy_if(ForwardIterator first, ForwardIterator last, 00103 OutputIterator result, Predicate pred, const T& new_value) 00104 { 00105 return std::replace_copy_if(first, last, result, boost::bind(pred, _1), new_value); 00106 } 00107 00113 template <class ForwardRange, class OutputIterator, class Predicate, class T> 00114 inline OutputIterator 00115 replace_copy_if(ForwardRange& range, OutputIterator result, Predicate pred, const T& new_value) 00116 { 00117 return adobe::replace_copy_if(boost::begin(range), boost::end(range), result, pred, new_value); 00118 } 00119 00125 template <class ForwardRange, class OutputIterator, class Predicate, class T> 00126 inline OutputIterator 00127 replace_copy_if(const ForwardRange& range, OutputIterator result, 00128 Predicate pred, const T& new_value) 00129 { 00130 return adobe::replace_copy_if(boost::begin(range), boost::end(range), result, pred, new_value); 00131 } 00132 00133 /*************************************************************************************************/ 00134 00135 } // namespace adobe 00136 00137 /*************************************************************************************************/ 00138 00139 #endif 00140 00141 /*************************************************************************************************/ |