1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // <numeric> 10 11 // Became constexpr in C++20 12 // template <class ForwardIterator, class T> 13 // void iota(ForwardIterator first, ForwardIterator last, T value); 14 15 #include <numeric> 16 #include <cassert> 17 18 #include "test_macros.h" 19 #include "test_iterators.h" 20 21 template <class InIter> 22 TEST_CONSTEXPR_CXX20 void test()23 test() 24 { 25 int ia[] = {1, 2, 3, 4, 5}; 26 int ir[] = {5, 6, 7, 8, 9}; 27 const unsigned s = sizeof(ia) / sizeof(ia[0]); 28 std::iota(InIter(ia), InIter(ia+s), 5); 29 for (unsigned i = 0; i < s; ++i) 30 assert(ia[i] == ir[i]); 31 } 32 33 TEST_CONSTEXPR_CXX20 bool test()34 test() 35 { 36 test<forward_iterator<int*> >(); 37 test<bidirectional_iterator<int*> >(); 38 test<random_access_iterator<int*> >(); 39 test<int*>(); 40 41 return true; 42 } 43 main(int,char **)44 int main(int, char**) 45 { 46 test(); 47 #if TEST_STD_VER > 17 48 static_assert(test()); 49 #endif 50 return 0; 51 } 52