~ubuntu-branches/ubuntu/trusty/libc++/trusty

« back to all changes in this revision

Viewing changes to libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.pass.cpp

  • Committer: Package Import Robot
  • Author(s): Andrej Belym
  • Date: 2012-06-02 19:25:47 UTC
  • Revision ID: package-import@ubuntu.com-20120602192547-b6ta950a8ckc9um2
Tags: upstream-1.0~svn160132
ImportĀ upstreamĀ versionĀ 1.0~svn160132

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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(pointer) ctor
 
15
 
 
16
#include <memory>
 
17
#include <cassert>
 
18
 
 
19
// unique_ptr(pointer) ctor should only require default Deleter ctor
 
20
 
 
21
struct A
 
22
{
 
23
    static int count;
 
24
    A() {++count;}
 
25
    A(const A&) {++count;}
 
26
    ~A() {--count;}
 
27
};
 
28
 
 
29
int A::count = 0;
 
30
 
 
31
class Deleter
 
32
{
 
33
    int state_;
 
34
 
 
35
    Deleter(Deleter&);
 
36
    Deleter& operator=(Deleter&);
 
37
 
 
38
public:
 
39
    Deleter() : state_(5) {}
 
40
 
 
41
    int state() const {return state_;}
 
42
 
 
43
    void operator()(A* p) {delete p;}
 
44
};
 
45
 
 
46
int main()
 
47
{
 
48
    {
 
49
    A* p = new A;
 
50
    assert(A::count == 1);
 
51
    std::unique_ptr<A> s(p);
 
52
    assert(s.get() == p);
 
53
    }
 
54
    assert(A::count == 0);
 
55
    {
 
56
    A* p = new A;
 
57
    assert(A::count == 1);
 
58
    std::unique_ptr<A, Deleter> s(p);
 
59
    assert(s.get() == p);
 
60
    assert(s.get_deleter().state() == 5);
 
61
    }
 
62
    assert(A::count == 0);
 
63
}