y3c-stl 0.3.3
Friendly C++ STL wrapper with automatic stacktrace
Loading...
Searching...
No Matches
shared_ptr-unwrap-ref.cc

‍example output:

100
y3c-stl terminated: undefined behavior detected (ub_access_deleted)
at y3c::unwrap(y3c::wrap<int&>): attempted to access the deleted value.
Stack trace (most recent call first):
#0 0x0000559306c40722 in main at /home/runner/work/y3c-stl/y3c-stl/build/../examples/shared_ptr-unwrap-ref.cc:9:24
7: std::cout << unwrap(ref) << std::endl;
8: a.reset();
9: std::cout << unwrap(ref) << std::endl;
10: }
値型wrap: base_type型のデータと、このデータの生存状態を管理するクラス
Definition wrap.h:26
Definition array.h:8
std::array< T, N > & unwrap(array< T, N > &wrapper) noexcept
Definition array.h:372
#include <y3c/memory>
#include <iostream>
int main() {
y3c::shared_ptr<int> a = std::make_shared<int>(100);
std::cout << unwrap(ref) << std::endl;
a.reset();
std::cout << unwrap(ref) << std::endl;
}
所有権を共有するスマートポインタ (std::shared_ptr)
Definition shared_ptr.h:28
void reset() noexcept
所有権を放棄
Definition shared_ptr.h:152
参照型wrap: element_type型のデータへの参照を持つクラス
Definition wrap.h:168