diff options
Diffstat (limited to 'common/algorithm.h')
-rw-r--r-- | common/algorithm.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/common/algorithm.h b/common/algorithm.h index cbd6eae708..13cdd9f991 100644 --- a/common/algorithm.h +++ b/common/algorithm.h @@ -270,5 +270,26 @@ T gcd(T a, T b) { #pragma warning(pop) #endif +/** + * Replacement algorithm for iterables. + * + * Replaces all occurrences of "original" in [begin, end) with occurrences of "replaced". + * + * @param[in, out] begin: First element to be examined. + * @param[in] end: Last element in the seubsection. Not examined. + * @param[in] original: Elements to be replaced. + * @param[in] replaced: Element to replace occurrences of "original". + * + * @note Usage examples and unit tests may be found in "test/common/algorithm.h" + */ +template<class It, class Dat> +void replace(It begin, It end, const Dat &original, const Dat &replaced) { + for (; begin != end; ++begin) { + if (*begin == original) { + *begin = replaced; + } + } +} + } // End of namespace Common #endif |