- memory[meta header]
- std[meta namespace]
- function template[meta id-type]
- cpp11[meta cpp]
namespace std {
template <class T>
shared_ptr<T> atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r,
memory_order order);
}- memory_order[link /reference/atomic/memory_order.md]
メモリオーダーを指定して、shared_ptrオブジェクトを、アトミックに入れ替える。
p != nullptrであること。
p->swap(r)相当のことを、アトミックに実行する。
変更前の*pを返す。
投げない
#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_explicit(
&a, b, std::memory_order_acquire);
std::cout << *a << std::endl;
std::cout << *prev_state << std::endl;
}- std::atomic_exchange_explicit[color ff0000]
2
1
- C++11
- Clang, C++11 mode: 3.3
- GCC, C++11 mode: 5.0
- ICC: ??
- Visual C++: 2012, 2013