// { dg-options "-std=gnu++17" } // { dg-do run { target c++17 } } // Copyright (C) 2019 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 3, or (at your option) // any later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License along // with this library; see the file COPYING3. If not see // . // C++17 29.8.7 [exclusive.scan] #include #include #include #include int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; using __gnu_test::test_container; using __gnu_test::input_iterator_wrapper; using __gnu_test::output_iterator_wrapper; /* template OutputIterator exclusive_scan(InputIterator, InputIterator, OutputIterator, T); */ void test01() { int out[10]; test_container co(out); test_container ca(a); auto end = std::exclusive_scan(ca.begin(), ca.end(), co.begin(), 5); static_assert(std::is_same_v); VERIFY( end.ptr == out+10 ); VERIFY( out[0] == 5 ); VERIFY( out[1] == 6 ); VERIFY( out[2] == 8 ); VERIFY( out[3] == 11 ); VERIFY( out[4] == 15 ); VERIFY( out[5] == 20 ); VERIFY( out[6] == 26 ); VERIFY( out[7] == 33 ); VERIFY( out[8] == 41 ); VERIFY( out[9] == 50 ); } /* template OutputIterator exclusive_scan(InputIterator, InputIterator, OutputIterator, T, BinaryOperation); */ void test02() { int out[10]; test_container co(out); test_container ca(a); auto end = std::exclusive_scan(ca.begin(), ca.end(), co.begin(), 2, [](int i, int j) { return 2*i + 2*j; }); static_assert(std::is_same_v); VERIFY( end.ptr == out+10 ); VERIFY( out[0] == 2 ); VERIFY( out[1] == 6 ); VERIFY( out[2] == 16 ); VERIFY( out[3] == 38 ); VERIFY( out[4] == 84 ); VERIFY( out[5] == 178 ); VERIFY( out[6] == 368 ); VERIFY( out[7] == 750 ); VERIFY( out[8] == 1516 ); VERIFY( out[9] == 3050 ); } int main() { test01(); test02(); }