Debian Codegraph @

libstdc++-v3/testsuite/20_util/smartptr.adapt/inout_ptr/1.cc

raw
1 // { dg-do run { target c++23 } }
2
3 #include <memory>
4 #include <testsuite_hooks.h>
5
6 // C++23 [inout.ptr.t] Class template inout_ptr_t
7
8 struct star_fish* star_fish_alloc();
9 int star_fish_populate(struct star_fish** ps, const char* description);
10
11 struct star_fish_deleter {
12 void operator() (struct star_fish* c) const noexcept;
13 };
14
15 using star_fish_ptr = std::unique_ptr<star_fish, star_fish_deleter>;
16
17 // Example 1 from [inout.ptr.t]
18 int main(int, char**)
19 {
20 star_fish_ptr peach(star_fish_alloc());
21 // ...
22 // used, need to re-make
23 int err = star_fish_populate(std::inout_ptr(peach), "caring clown-fish liker");
24 return 0;
25 }
26
27 #include <cstdint>
28
29 star_fish* star_fish_alloc()
30 {
31 static std::uintptr_t counter = 1;
32 return reinterpret_cast<star_fish*>(counter++);
33 }
34
35 void star_fish_deleter::operator()(star_fish* c) const noexcept
36 {
37 static std::uintptr_t counter = 1;
38 VERIFY(reinterpret_cast<std::uintptr_t>(c) == counter++);
39 }
40
41 int star_fish_populate(star_fish** ps, const char*)
42 {
43 VERIFY(ps);
44 star_fish_deleter()(*ps);
45 *ps = star_fish_alloc();
46 return 0;
47 }