Debian Codegraph @

libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_value_construct/constexpr.cc

raw
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()
13 {
14 static_assert(std::default_initializable<T>);
15 static_assert(std::equality_comparable<T>);
16
17 constexpr std::size_t size = 42;
18 std::allocator<T> alloc;
19 T* ptr = alloc.allocate(size);
20
21 auto check = [&]() -> bool
22 {
23 return std::all_of(ptr, ptr + size, [](auto &&x) { return x == T(); });
24 };
25
26 std::uninitialized_value_construct(ptr, ptr + size);
27 if (!check())
28 return false;
29 std::destroy(ptr, ptr + size);
30
31 std::uninitialized_value_construct_n(ptr, size);
32 if (!check())
33 return false;
34 std::destroy_n(ptr, size);
35
36 std::span<T> storage(ptr, ptr + size);
37 std::ranges::uninitialized_value_construct(storage);
38 if (!check())
39 return false;
40 std::ranges::destroy(storage);
41
42 std::ranges::uninitialized_value_construct_n(ptr, size);
43 if (!check())
44 return false;
45 std::ranges::destroy_n(ptr, size);
46
47 alloc.deallocate(ptr, size);
48 return true;
49 }
50
51 constexpr
52 bool
53 test01()
54 {
55 return
56 test01_impl<char>() &&
57 test01_impl<int>() &&
58 test01_impl<double>() &&
59 #if _GLIBCXX_USE_CXX11_ABI
60 test01_impl<std::string>() &&
61 #endif
62 test01_impl<std::vector<int>>() &&
63 test01_impl<std::unique_ptr<int>>();
64 }
65
66 static_assert(test01());