libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

make_shared.volatile.pass.cpp (1501B)


      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 // <memory>
     11 
     12 // shared_ptr
     13 
     14 // template<class T, class... Args> shared_ptr<T> make_shared(Args&&... args);
     15 
     16 #include <memory>
     17 #include <cassert>
     18 
     19 template <typename T>
     20 void test(const T &t0)
     21 {
     22     {
     23     T t1 = t0;
     24     std::shared_ptr<T> p0 = std::make_shared<T>(t0);
     25     std::shared_ptr<T> p1 = std::make_shared<T>(t1);
     26     assert(*p0 == t0);
     27     assert(*p1 == t1);
     28     }
     29 
     30     {
     31     const T t1 = t0;
     32     std::shared_ptr<const T> p0 = std::make_shared<const T>(t0);
     33     std::shared_ptr<const T> p1 = std::make_shared<const T>(t1);
     34     assert(*p0 == t0);
     35     assert(*p1 == t1);
     36     }
     37 
     38     {
     39     volatile T t1 = t0;
     40     std::shared_ptr<volatile T> p0 = std::make_shared<volatile T>(t0);
     41     std::shared_ptr<volatile T> p1 = std::make_shared<volatile T>(t1);
     42     assert(*p0 == t0);
     43     assert(*p1 == t1);
     44     }
     45 
     46     {
     47     const volatile T t1 = t0;
     48     std::shared_ptr<const volatile T> p0 = std::make_shared<const volatile T>(t0);
     49     std::shared_ptr<const volatile T> p1 = std::make_shared<const volatile T>(t1);
     50     assert(*p0 == t0);
     51     assert(*p1 == t1);
     52     }
     53 
     54 }
     55 
     56 int main()
     57 {
     58     test<bool>(true);
     59     test<int>(3);
     60     test<double>(5.0);
     61 }