1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// UNSUPPORTED: no-threads
10
11// <memory>
12
13// shared_ptr
14
15// template <class T>
16// bool
17// atomic_compare_exchange_strong(shared_ptr<T>* p, shared_ptr<T>* v,
18// shared_ptr<T> w);
19
20// UNSUPPORTED: c++03
21
22#include <memory>
23
24#include <atomic>
25#include <cassert>
26
27#include "test_macros.h"
28
29int main(int, char**)
30{
31 {
32 std::shared_ptr<int> p(new int(4));
33 std::shared_ptr<int> v(new int(3));
34 std::shared_ptr<int> w(new int(2));
35 bool b = std::atomic_compare_exchange_strong(&p, &v, w);
36 assert(b == false);
37 assert(*p == 4);
38 assert(*v == 4);
39 assert(*w == 2);
40 }
41 {
42 std::shared_ptr<int> p(new int(4));
43 std::shared_ptr<int> v = p;
44 std::shared_ptr<int> w(new int(2));
45 bool b = std::atomic_compare_exchange_strong(&p, &v, w);
46 assert(b == true);
47 assert(*p == 2);
48 assert(*v == 4);
49 assert(*w == 2);
50 }
51
52 return 0;
53}
54

source code of libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_strong.pass.cpp