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, Predicate<auto, Iter::value_type> Pred, class T> 13 // requires OutputIterator<Iter, Iter::reference> 14 // && OutputIterator<Iter, const T&> 15 // && CopyConstructible<Pred> 16 // void 17 // replace_if(Iter first, Iter last, Pred pred, const T& new_value); 18 19 #include <algorithm> 20 #include <functional> 21 #include <cassert> 22 23 #include "test_iterators.h" 24 25 bool equalToTwo(int v) { return v == 2; } 26 27 template <class Iter> 28 void 29 test() 30 { 31 int ia[] = {0, 1, 2, 3, 4}; 32 const unsigned sa = sizeof(ia)/sizeof(ia[0]); 33 std::replace_if(Iter(ia), Iter(ia+sa), equalToTwo, 5); 34 assert(ia[0] == 0); 35 assert(ia[1] == 1); 36 assert(ia[2] == 5); 37 assert(ia[3] == 3); 38 assert(ia[4] == 4); 39 } 40 41 int main() 42 { 43 test<forward_iterator<int*> >(); 44 test<bidirectional_iterator<int*> >(); 45 test<random_access_iterator<int*> >(); 46 test<int*>(); 47 } 48