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
25template <class Iter>
26void
27test()
28{
29    int ia[] = {0, 1, 2, 3, 4};
30    const unsigned sa = sizeof(ia)/sizeof(ia[0]);
31    std::replace_if(Iter(ia), Iter(ia+sa), std::bind2nd(std::equal_to<int>(), 2), 5);
32    assert(ia[0] == 0);
33    assert(ia[1] == 1);
34    assert(ia[2] == 5);
35    assert(ia[3] == 3);
36    assert(ia[4] == 4);
37}
38
39int main()
40{
41    test<forward_iterator<int*> >();
42    test<bidirectional_iterator<int*> >();
43    test<random_access_iterator<int*> >();
44    test<int*>();
45}
46