namespace std {
template <class T>
shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
}
概要
shared_ptr
オブジェクトを、アトミックに入れ替える。
要件
p != nullptr
であること。
戻り値
例外
投げない
例
#include <iostream>
#include <memory>
int main()
{
std::shared_ptr<int> a(new int(1));
std::shared_ptr<int> b(new int(2));
std::shared_ptr<int> prev_state = std::atomic_exchange(&a, b);
std::cout << *a << std::endl;
std::cout << *prev_state << std::endl;
}
出力
2
1
バージョン
言語
- C++11
処理系
- Clang: 3.3
- GCC: 5.0
- ICC: ??
- Visual C++: 2012, 2013