stlab.adobe.com Adobe Systems Incorporated
replace.hpp
Go to the documentation of this file.
1 /*
2  Copyright 2005-2007 Adobe Systems Incorporated
3  Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
4  or a copy at http://stlab.adobe.com/licenses.html)
5 */
6 
7 /*************************************************************************************************/
8 
9 #ifndef ADOBE_ALGORITHM_REPLACE_HPP
10 #define ADOBE_ALGORITHM_REPLACE_HPP
11 
12 #include <adobe/config.hpp>
13 
14 #include <boost/range/begin.hpp>
15 #include <boost/range/end.hpp>
16 #include <boost/bind.hpp>
17 
18 #include <algorithm>
19 
20 /*************************************************************************************************/
21 
22 namespace adobe {
23 
24 /*************************************************************************************************/
35 /*************************************************************************************************/
41 template <class ForwardRange, class T>
42 inline void replace(ForwardRange& range, const T& old_value, const T& new_value)
43 {
44  std::replace(boost::begin(range), boost::end(range), old_value, new_value);
45 }
46 
52 template <class ForwardIterator, class Predicate, class T>
53 inline void
54 replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value)
55 {
56  std::replace_if(first, last, boost::bind(pred, _1), new_value);
57 }
58 
64 template <class ForwardRange, class Predicate, class T>
65 inline void replace_if(ForwardRange& range, Predicate pred, const T& new_value)
66 {
67  adobe::replace_if(boost::begin(range), boost::end(range), pred, new_value);
68 }
69 
75 template <class ForwardRange, class OutputIterator, class T>
76 inline OutputIterator
77 replace_copy(ForwardRange& range, OutputIterator result, const T& old_value, const T& new_value)
78 {
79  return std::replace_copy(boost::begin(range), boost::end(range), result, old_value, new_value);
80 }
81 
87 template <class ForwardRange, class OutputIterator, class T>
88 inline OutputIterator
89 replace_copy(const ForwardRange& range, OutputIterator result,
90  const T& old_value, const T& new_value)
91 {
92  return std::replace_copy(boost::begin(range), boost::end(range), result, old_value, new_value);
93 }
94 
100 template <class ForwardIterator, class OutputIterator, class Predicate, class T>
101 inline OutputIterator
102 replace_copy_if(ForwardIterator first, ForwardIterator last,
103  OutputIterator result, Predicate pred, const T& new_value)
104 {
105  return std::replace_copy_if(first, last, result, boost::bind(pred, _1), new_value);
106 }
107 
113 template <class ForwardRange, class OutputIterator, class Predicate, class T>
114 inline OutputIterator
115 replace_copy_if(ForwardRange& range, OutputIterator result, Predicate pred, const T& new_value)
116 {
117  return adobe::replace_copy_if(boost::begin(range), boost::end(range), result, pred, new_value);
118 }
119 
125 template <class ForwardRange, class OutputIterator, class Predicate, class T>
126 inline OutputIterator
127 replace_copy_if(const ForwardRange& range, OutputIterator result,
128  Predicate pred, const T& new_value)
129 {
130  return adobe::replace_copy_if(boost::begin(range), boost::end(range), result, pred, new_value);
131 }
132 
133 /*************************************************************************************************/
134 
135 } // namespace adobe
136 
137 /*************************************************************************************************/
138 
139 #endif
140 
141 /*************************************************************************************************/

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google