| 1 | // { dg-do run { target c++20 } } |
| 2 | // Bug libstdc++/108487 |
| 3 | // ~20-30x slowdown in populating std::vector from std::ranges::iota_view |
| 4 | |
| 5 | #include <ranges> |
| 6 | #include <testsuite_hooks.h> |
| 7 | #include <testsuite_allocator.h> |
| 8 | |
| 9 | void |
| 10 | test_pr108487() |
| 11 | { |
| 12 | using __gnu_test::tracker_allocator; |
| 13 | using __gnu_test::tracker_allocator_counter; |
| 14 | auto r = std::ranges::iota_view{0, 20}; |
| 15 | tracker_allocator_counter::reset(); |
| 16 | std::vector<int, tracker_allocator<int>> v{r.begin(), r.end()}; |
| 17 | const std::size_t bytes = v.capacity() * sizeof(v.front()); |
| 18 | VERIFY( tracker_allocator_counter::get_allocation_count() == bytes ); |
| 19 | } |
| 20 | |
| 21 | int main() |
| 22 | { |
| 23 | test_pr108487(); |
| 24 | } |