]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / utilities / memory / unique.ptr / unique.ptr.runtime / unique.ptr.runtime.ctor / move02.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 ctor
15
16 // test move ctor.  Should only require a MoveConstructible deleter, or if
17 //    deleter is a reference, not even that.
18
19 #include <memory>
20 #include <cassert>
21
22 #include "../../deleter.h"
23
24 struct A
25 {
26     static int count;
27     A() {++count;}
28     A(const A&) {++count;}
29     ~A() {--count;}
30 };
31
32 int A::count = 0;
33
34
35 std::unique_ptr<A[]>
36 source1()
37 {
38     return std::unique_ptr<A[]>(new A[3]);
39 }
40
41 void sink1(std::unique_ptr<A[]>)
42 {
43 }
44
45 std::unique_ptr<A[], Deleter<A[]> >
46 source2()
47 {
48     return std::unique_ptr<A[], Deleter<A[]> >(new A[3]);
49 }
50
51 void sink2(std::unique_ptr<A[], Deleter<A[]> >)
52 {
53 }
54
55 std::unique_ptr<A[], NCDeleter<A[]>&>
56 source3()
57 {
58     static NCDeleter<A[]> d;
59     return std::unique_ptr<A[], NCDeleter<A[]>&>(new A[3], d);
60 }
61
62 void sink3(std::unique_ptr<A[], NCDeleter<A[]>&>)
63 {
64 }
65
66 int main()
67 {
68     sink1(source1());
69     sink2(source2());
70     sink3(source3());
71     assert(A::count == 0);
72 }