15a83710eSEric Fiselier //===----------------------------------------------------------------------===// 25a83710eSEric Fiselier // 35a83710eSEric Fiselier // The LLVM Compiler Infrastructure 45a83710eSEric Fiselier // 55a83710eSEric Fiselier // This file is dual licensed under the MIT and the University of Illinois Open 65a83710eSEric Fiselier // Source Licenses. See LICENSE.TXT for details. 75a83710eSEric Fiselier // 85a83710eSEric Fiselier //===----------------------------------------------------------------------===// 95a83710eSEric Fiselier 105a83710eSEric Fiselier // <algorithm> 115a83710eSEric Fiselier 125a83710eSEric Fiselier // template<ForwardIterator Iter, class T> 135a83710eSEric Fiselier // requires OutputIterator<Iter, Iter::reference> 145a83710eSEric Fiselier // && OutputIterator<Iter, const T&> 155a83710eSEric Fiselier // && HasEqualTo<Iter::value_type, T> 16*12c7423fSMarshall Clow // constexpr void // constexpr after C++17 175a83710eSEric Fiselier // replace(Iter first, Iter last, const T& old_value, const T& new_value); 185a83710eSEric Fiselier 195a83710eSEric Fiselier #include <algorithm> 205a83710eSEric Fiselier #include <cassert> 215a83710eSEric Fiselier 22*12c7423fSMarshall Clow #include "test_macros.h" 235a83710eSEric Fiselier #include "test_iterators.h" 245a83710eSEric Fiselier 25*12c7423fSMarshall Clow 26*12c7423fSMarshall Clow #if TEST_STD_VER > 17 27*12c7423fSMarshall Clow TEST_CONSTEXPR bool test_constexpr() { 28*12c7423fSMarshall Clow int ia[] = {0, 1, 2, 3, 4}; 29*12c7423fSMarshall Clow const int expected[] = {0, 1, 5, 3, 4}; 30*12c7423fSMarshall Clow 31*12c7423fSMarshall Clow std::replace(std::begin(ia), std::end(ia), 2, 5); 32*12c7423fSMarshall Clow return std::equal(std::begin(ia), std::end(ia), std::begin(expected), std::end(expected)) 33*12c7423fSMarshall Clow ; 34*12c7423fSMarshall Clow } 35*12c7423fSMarshall Clow #endif 36*12c7423fSMarshall Clow 375a83710eSEric Fiselier template <class Iter> 385a83710eSEric Fiselier void 395a83710eSEric Fiselier test() 405a83710eSEric Fiselier { 415a83710eSEric Fiselier int ia[] = {0, 1, 2, 3, 4}; 425a83710eSEric Fiselier const unsigned sa = sizeof(ia)/sizeof(ia[0]); 435a83710eSEric Fiselier std::replace(Iter(ia), Iter(ia+sa), 2, 5); 445a83710eSEric Fiselier assert(ia[0] == 0); 455a83710eSEric Fiselier assert(ia[1] == 1); 465a83710eSEric Fiselier assert(ia[2] == 5); 475a83710eSEric Fiselier assert(ia[3] == 3); 485a83710eSEric Fiselier assert(ia[4] == 4); 495a83710eSEric Fiselier } 505a83710eSEric Fiselier 515a83710eSEric Fiselier int main() 525a83710eSEric Fiselier { 535a83710eSEric Fiselier test<forward_iterator<int*> >(); 545a83710eSEric Fiselier test<bidirectional_iterator<int*> >(); 555a83710eSEric Fiselier test<random_access_iterator<int*> >(); 565a83710eSEric Fiselier test<int*>(); 57*12c7423fSMarshall Clow 58*12c7423fSMarshall Clow #if TEST_STD_VER > 17 59*12c7423fSMarshall Clow static_assert(test_constexpr()); 60*12c7423fSMarshall Clow #endif 615a83710eSEric Fiselier } 62