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 //   constexpr void      // constexpr after C++17
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_macros.h"
23 #include "test_iterators.h"
24 
25 
26 #if TEST_STD_VER > 17
test_constexpr()27 TEST_CONSTEXPR bool test_constexpr() {
28           int ia[]       = {0, 1, 2, 3, 4};
29     const int expected[] = {0, 1, 5, 3, 4};
30 
31     std::replace(std::begin(ia), std::end(ia), 2, 5);
32     return std::equal(std::begin(ia), std::end(ia), std::begin(expected), std::end(expected))
33         ;
34     }
35 #endif
36 
37 template <class Iter>
38 void
test()39 test()
40 {
41     int ia[] = {0, 1, 2, 3, 4};
42     const unsigned sa = sizeof(ia)/sizeof(ia[0]);
43     std::replace(Iter(ia), Iter(ia+sa), 2, 5);
44     assert(ia[0] == 0);
45     assert(ia[1] == 1);
46     assert(ia[2] == 5);
47     assert(ia[3] == 3);
48     assert(ia[4] == 4);
49 }
50 
main()51 int main()
52 {
53     test<forward_iterator<int*> >();
54     test<bidirectional_iterator<int*> >();
55     test<random_access_iterator<int*> >();
56     test<int*>();
57 
58 #if TEST_STD_VER > 17
59     static_assert(test_constexpr());
60 #endif
61 }
62