]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/nullptr.pass.cpp
Vendor import of libc++ 4.0.0 release r297347:
[FreeBSD/FreeBSD.git] / test / std / utilities / smartptr / unique.ptr / unique.ptr.class / unique.ptr.asgn / nullptr.pass.cpp
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 // unique_ptr
13
14 // Test unique_ptr move assignment
15
16 #include <memory>
17 #include <cassert>
18
19 #include "unique_ptr_test_helper.h"
20
21 // test assignment from null
22
23 template <bool IsArray>
24 void test_basic() {
25   typedef typename std::conditional<IsArray, A[], A>::type VT;
26   const int expect_alive = IsArray ? 5 : 1;
27   {
28     std::unique_ptr<VT> s2(newValue<VT>(expect_alive));
29     assert(A::count == expect_alive);
30     s2 = nullptr;
31     assert(A::count == 0);
32     assert(s2.get() == 0);
33   }
34   assert(A::count == 0);
35 }
36
37 int main() {
38   test_basic</*IsArray*/ false>();
39   test_basic<true>();
40 }