| 1 |
// { dg-do run { target c++23 } } |
| 2 |
|
| 3 |
#include <generator> |
| 4 |
#include <testsuite_hooks.h> |
| 5 |
#include <testsuite_allocator.h> |
| 6 |
|
| 7 |
template<typename... Args> |
| 8 |
std::pmr::generator<int> |
| 9 |
gen(Args...) |
| 10 |
{ |
| 11 |
co_yield 1; |
| 12 |
co_yield 2; |
| 13 |
} |
| 14 |
|
| 15 |
struct S |
| 16 |
{ |
| 17 |
template<typename... Args> |
| 18 |
std::pmr::generator<char> |
| 19 |
gen(Args...) |
| 20 |
{ |
| 21 |
co_yield '1'; |
| 22 |
co_yield '2'; |
| 23 |
} |
| 24 |
|
| 25 |
template<typename Self, typename... Args> |
| 26 |
std::pmr::generator<long long> |
| 27 |
genx(this Self& self, Args...) |
| 28 |
{ |
| 29 |
co_yield 1LL; |
| 30 |
co_yield 2LL; |
| 31 |
} |
| 32 |
}; |
| 33 |
|
| 34 |
int |
| 35 |
main() |
| 36 |
{ |
| 37 |
__gnu_test::memory_resource mr; |
| 38 |
for (auto _ : gen()) |
| 39 |
VERIFY(mr.number_of_active_allocations() == 0); |
| 40 |
|
| 41 |
for (auto _ : gen(std::allocator_arg)) |
| 42 |
VERIFY(mr.number_of_active_allocations() == 0); |
| 43 |
|
| 44 |
for (auto _ : gen(std::allocator_arg, std::pmr::new_delete_resource())) |
| 45 |
VERIFY(mr.number_of_active_allocations() == 0); |
| 46 |
|
| 47 |
#if __cpp_exceptions |
| 48 |
try { |
| 49 |
for (auto _ : gen(std::allocator_arg, std::pmr::null_memory_resource())) |
| 50 |
VERIFY(false); |
| 51 |
} catch (const std::bad_alloc&) { |
| 52 |
} |
| 53 |
#endif |
| 54 |
|
| 55 |
VERIFY(mr.number_of_active_allocations() == 0); |
| 56 |
|
| 57 |
for (auto _ : gen(std::allocator_arg , &mr)) |
| 58 |
VERIFY(mr.number_of_active_allocations() == 1); |
| 59 |
|
| 60 |
VERIFY(mr.number_of_active_allocations() == 0); |
| 61 |
|
| 62 |
S s; |
| 63 |
for (auto _ : s.gen(std::allocator_arg , &mr)) |
| 64 |
VERIFY(mr.number_of_active_allocations() == 1); |
| 65 |
|
| 66 |
VERIFY(mr.number_of_active_allocations() == 0); |
| 67 |
for (auto _ : s.genx(std::allocator_arg , &mr)) |
| 68 |
VERIFY(mr.number_of_active_allocations() == 1); |
| 69 |
|
| 70 |
VERIFY(mr.number_of_active_allocations() == 0); |
| 71 |
} |