Debian Codegraph @

libstdc++-v3/testsuite/24_iterators/range_generators/01.cc

raw
1 // { dg-do run { target c++23 } }
2 // Copyright (C) 2023-2025 Free Software Foundation, Inc.
3 //
4 // This file is part of the GNU ISO C++ Library. This library is free
5 // software; you can redistribute it and/or modify it under the
6 // terms of the GNU General Public License as published by the
7 // Free Software Foundation; either version 3, or (at your option)
8 // any later version.
9
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14
15 // You should have received a copy of the GNU General Public License along
16 // with this library; see the file COPYING3. If not see
17 // <http://www.gnu.org/licenses/>.
18
19 #include <generator>
20 #include <iostream>
21
22 // basic example
23 std::generator<int>
24 bar()
25 {
26 co_yield 3;
27 co_yield 4;
28 }
29
30 std::generator<int>
31 foo()
32 {
33 co_yield 1;
34 co_yield 2;
35 co_yield std::ranges::elements_of { bar() };
36 co_yield 5;
37 }
38
39 int
40 main()
41 {
42 for (auto x : foo())
43 std::cout << x << '\n';
44 }
45
46 // { dg-output {1(\n|\r\n|\r)} }
47 // { dg-output {2(\n|\r\n|\r)} }
48 // { dg-output {3(\n|\r\n|\r)} }
49 // { dg-output {4(\n|\r\n|\r)} }
50 // { dg-output {5(\n|\r\n|\r)} }