| 1 |
// { dg-do compile { target c++26 } } |
| 2 |
|
| 3 |
#include <algorithm> |
| 4 |
#include <memory> |
| 5 |
#include <span> |
| 6 |
#include <string> |
| 7 |
#include <vector> |
| 8 |
|
| 9 |
template<typename T> |
| 10 |
constexpr |
| 11 |
bool |
| 12 |
test01_impl(std::vector<T> input) |
| 13 |
{ |
| 14 |
static_assert(std::copy_constructible<T>); |
| 15 |
static_assert(std::equality_comparable<T>); |
| 16 |
|
| 17 |
const std::size_t input_size = input.size(); |
| 18 |
std::allocator<T> alloc; |
| 19 |
T* ptr = alloc.allocate(input_size); |
| 20 |
|
| 21 |
std::uninitialized_copy(input.begin(), input.end(), ptr); |
| 22 |
if (!std::equal(input.begin(), input.end(), ptr, ptr + input_size)) |
| 23 |
return false; |
| 24 |
std::destroy(ptr, ptr + input_size); |
| 25 |
|
| 26 |
std::uninitialized_copy_n(input.begin(), input_size, ptr); |
| 27 |
if (!std::equal(input.begin(), input.end(), ptr, ptr + input_size)) |
| 28 |
return false; |
| 29 |
std::destroy_n(ptr, input_size); |
| 30 |
|
| 31 |
std::span<T> output(ptr, ptr + input_size); |
| 32 |
std::ranges::uninitialized_copy(input, output); |
| 33 |
if (!std::ranges::equal(input, output)) |
| 34 |
return false; |
| 35 |
std::ranges::destroy(output); |
| 36 |
|
| 37 |
std::ranges::uninitialized_copy_n(input.begin(), input_size, ptr, ptr + input_size); |
| 38 |
if (!std::ranges::equal(input.begin(), input.end(), ptr, ptr + input_size)) |
| 39 |
return false; |
| 40 |
std::ranges::destroy_n(ptr, input_size); |
| 41 |
|
| 42 |
alloc.deallocate(ptr, input_size); |
| 43 |
return true; |
| 44 |
} |
| 45 |
|
| 46 |
constexpr |
| 47 |
bool |
| 48 |
test01() |
| 49 |
{ |
| 50 |
return |
| 51 |
test01_impl<char>({'a', 'b', 'c'}) && |
| 52 |
test01_impl<int>({1, 2, 3, 4}) && |
| 53 |
test01_impl<double>({1.0, 2.0, 3.0, 4.0}) && |
| 54 |
#if _GLIBCXX_USE_CXX11_ABI |
| 55 |
test01_impl<std::string>({"a", "b", "cc", "dddd", "eeeeeeeeeeeeeeee"}) && |
| 56 |
#endif |
| 57 |
test01_impl<std::vector<int>>({ {0}, {0, 1}, {0, 1, 2}}); |
| 58 |
} |
| 59 |
|
| 60 |
static_assert(test01()); |