Home | History | Annotate | Download | only in atomics.types.operations.req
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <atomic>
     11 
     12 // template <class T>
     13 //     T
     14 //     atomic_load_explicit(const volatile atomic<T>* obj, memory_order m);
     15 //
     16 // template <class T>
     17 //     T
     18 //     atomic_load_explicit(const atomic<T>* obj, memory_order m);
     19 
     20 #include <atomic>
     21 #include <type_traits>
     22 #include <cassert>
     23 
     24 template <class T>
     25 void
     26 test()
     27 {
     28     typedef std::atomic<T> A;
     29     A t;
     30     std::atomic_init(&t, T(1));
     31     assert(std::atomic_load_explicit(&t, std::memory_order_seq_cst) == T(1));
     32     volatile A vt;
     33     std::atomic_init(&vt, T(2));
     34     assert(std::atomic_load_explicit(&vt, std::memory_order_seq_cst) == T(2));
     35 }
     36 
     37 struct A
     38 {
     39     int i;
     40 
     41     explicit A(int d = 0) : i(d) {}
     42 
     43     friend bool operator==(const A& x, const A& y)
     44         {return x.i == y.i;}
     45 };
     46 
     47 int main()
     48 {
     49     test<A>();
     50     test<char>();
     51     test<signed char>();
     52     test<unsigned char>();
     53     test<short>();
     54     test<unsigned short>();
     55     test<int>();
     56     test<unsigned int>();
     57     test<long>();
     58     test<unsigned long>();
     59     test<long long>();
     60     test<unsigned long long>();
     61     test<wchar_t>();
     62 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
     63     test<char16_t>();
     64     test<char32_t>();
     65 #endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
     66     test<int*>();
     67     test<const int*>();
     68 }
     69