- memory[meta header]
- std[meta namespace]
- function template[meta id-type]
- cpp11[meta cpp]
namespace std {
template <class T>
shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
}shared_ptrオブジェクトを、アトミックに入れ替える。
p != nullptrであること。
atomic_exchange_explicit(p, r, memory_order_seq_cst)- atomic_exchange_explicit[link atomic_load_explicit.md]
- memory_order_seq_cst[link /reference/atomic/memory_order.md]
投げない
#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;
}- std::atomic_exchange[color ff0000]
2
1
- C++11
- Clang, C++11 mode: 3.3
- GCC, C++11 mode: 5.0
- ICC: ??
- Visual C++: 2012, 2013