Skip to content

Commit 724e44e

Browse files
authored
Update 011_memory_ranges_construct_at.cpp
1 parent d17327f commit 724e44e

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,26 @@
1-
1
1+
#include <iostream>
2+
#include <memory>
3+
4+
struct S {
5+
int x;
6+
float y;
7+
double z;
8+
9+
S(int x, float y, double z) : x{x}, y{y}, z{z} { std::cout << "S::S();\n"; }
10+
11+
~S() { std::cout << "S::~S();\n"; }
12+
13+
void print() const {
14+
std::cout << "S { x=" << x << "; y=" << y << "; z=" << z << "; };\n";
15+
}
16+
};
17+
18+
int main()
19+
{
20+
alignas(S) unsigned char buf[sizeof(S)];
21+
22+
S* ptr = std::ranges::construct_at(reinterpret_cast<S*>(buf), 42, 2.71828f, 3.1415);
23+
ptr->print();
24+
25+
std::ranges::destroy_at(ptr);
26+
}

0 commit comments

Comments
 (0)