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 get_deleter()
15
16 #include <memory>
17 #include <cassert>
18 #include "test_macros.h"
19
20 struct Deleter {
DeleterDeleter21 Deleter() {}
22
operator ()Deleter23 void operator()(void*) const {}
24
testDeleter25 int test() { return 5; }
testDeleter26 int test() const { return 6; }
27 };
28
29 template <bool IsArray>
test_basic()30 void test_basic() {
31 typedef typename std::conditional<IsArray, int[], int>::type VT;
32 {
33 std::unique_ptr<int, Deleter> p;
34 assert(p.get_deleter().test() == 5);
35 }
36 {
37 const std::unique_ptr<VT, Deleter> p;
38 assert(p.get_deleter().test() == 6);
39 }
40 {
41 typedef std::unique_ptr<VT, const Deleter&> UPtr;
42 const Deleter d;
43 UPtr p(nullptr, d);
44 const UPtr& cp = p;
45 ASSERT_SAME_TYPE(decltype(p.get_deleter()), const Deleter&);
46 ASSERT_SAME_TYPE(decltype(cp.get_deleter()), const Deleter&);
47 assert(p.get_deleter().test() == 6);
48 assert(cp.get_deleter().test() == 6);
49 }
50 {
51 typedef std::unique_ptr<VT, Deleter&> UPtr;
52 Deleter d;
53 UPtr p(nullptr, d);
54 const UPtr& cp = p;
55 ASSERT_SAME_TYPE(decltype(p.get_deleter()), Deleter&);
56 ASSERT_SAME_TYPE(decltype(cp.get_deleter()), Deleter&);
57 assert(p.get_deleter().test() == 5);
58 assert(cp.get_deleter().test() == 5);
59 }
60 }
61
main()62 int main() {
63 test_basic</*IsArray*/ false>();
64 test_basic<true>();
65 }
66