1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is dual licensed under the MIT and the University of Illinois Open 6// Source Licenses. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// <algorithm> 11 12// template<ForwardIterator Iter, class T> 13// requires OutputIterator<Iter, Iter::reference> 14// && OutputIterator<Iter, const T&> 15// && HasEqualTo<Iter::value_type, T> 16// void 17// replace(Iter first, Iter last, const T& old_value, const T& new_value); 18 19#include <algorithm> 20#include <cassert> 21 22#include "test_iterators.h" 23 24template <class Iter> 25void 26test() 27{ 28 int ia[] = {0, 1, 2, 3, 4}; 29 const unsigned sa = sizeof(ia)/sizeof(ia[0]); 30 std::replace(Iter(ia), Iter(ia+sa), 2, 5); 31 assert(ia[0] == 0); 32 assert(ia[1] == 1); 33 assert(ia[2] == 5); 34 assert(ia[3] == 3); 35 assert(ia[4] == 4); 36} 37 38int main() 39{ 40 test<forward_iterator<int*> >(); 41 test<bidirectional_iterator<int*> >(); 42 test<random_access_iterator<int*> >(); 43 test<int*>(); 44} 45