OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 #include "Test.h" | 7 #include "Test.h" |
8 #include "SkTemplates.h" | 8 #include "SkTemplates.h" |
| 9 #include <utility> |
9 | 10 |
10 namespace { | 11 namespace { |
11 class Moveable { | 12 class Moveable { |
12 public: | 13 public: |
13 Moveable() {} | 14 Moveable() {} |
14 Moveable(Moveable&&) {} | 15 Moveable(Moveable&&) {} |
15 Moveable& operator=(Moveable&&) { return *this; } | 16 Moveable& operator=(Moveable&&) { return *this; } |
16 private: | 17 private: |
17 Moveable(const Moveable&); | 18 Moveable(const Moveable&); |
18 Moveable& operator=(const Moveable&); | 19 Moveable& operator=(const Moveable&); |
19 }; | 20 }; |
20 template <typename T> void deleter(T*) { } | 21 template <typename T> void deleter(T*) { } |
21 template <typename T> struct Deleter { | 22 template <typename T> struct Deleter { |
22 void operator()(T* t) { delete static_cast<const Moveable*>(t); } | 23 void operator()(T* t) { delete static_cast<const Moveable*>(t); } |
23 }; | 24 }; |
24 } // namespace | 25 } // namespace |
25 | 26 |
26 DEF_TEST(CPlusPlusEleven_RvalueAndMove, r) { | 27 DEF_TEST(CPlusPlusEleven_RvalueAndMove, r) { |
27 Moveable src1; Moveable dst1(skstd::move(src1)); | 28 Moveable src1; Moveable dst1(std::move(src1)); |
28 Moveable src2, dst2; dst2 = skstd::move(src2); | 29 Moveable src2, dst2; dst2 = std::move(src2); |
29 } | 30 } |
30 | 31 |
31 #define TOO_BIG "The unique_ptr was bigger than expected." | 32 #define TOO_BIG "The unique_ptr was bigger than expected." |
32 #define WEIRD_SIZE "The unique_ptr was a different size than expected." | 33 #define WEIRD_SIZE "The unique_ptr was a different size than expected." |
33 | 34 |
34 DEF_TEST(CPlusPlusEleven_UniquePtr, r) { | 35 DEF_TEST(CPlusPlusEleven_UniquePtr, r) { |
35 struct SmallUniquePtr { | 36 struct SmallUniquePtr { |
36 Moveable* p; | 37 Moveable* p; |
37 }; | 38 }; |
38 struct BigUniquePtr { | 39 struct BigUniquePtr { |
39 void(*d)(Moveable*); | 40 void(*d)(Moveable*); |
40 Moveable* p; | 41 Moveable* p; |
41 }; | 42 }; |
42 | 43 |
43 static_assert(sizeof(skstd::unique_ptr<Moveable>) == sizeof(SmallUniquePtr),
TOO_BIG); | 44 static_assert(sizeof(skstd::unique_ptr<Moveable>) == sizeof(SmallUniquePtr),
TOO_BIG); |
44 static_assert(sizeof(skstd::unique_ptr<Moveable[]>) == sizeof(SmallUniquePtr
), TOO_BIG); | 45 static_assert(sizeof(skstd::unique_ptr<Moveable[]>) == sizeof(SmallUniquePtr
), TOO_BIG); |
45 | 46 |
46 using proc = void(*)(Moveable*); | 47 using proc = void(*)(Moveable*); |
47 static_assert(sizeof(skstd::unique_ptr<Moveable, proc>) == sizeof(BigUniqueP
tr), WEIRD_SIZE); | 48 static_assert(sizeof(skstd::unique_ptr<Moveable, proc>) == sizeof(BigUniqueP
tr), WEIRD_SIZE); |
48 static_assert(sizeof(skstd::unique_ptr<Moveable[], proc>) == sizeof(BigUniqu
ePtr), WEIRD_SIZE); | 49 static_assert(sizeof(skstd::unique_ptr<Moveable[], proc>) == sizeof(BigUniqu
ePtr), WEIRD_SIZE); |
49 | 50 |
50 { | 51 { |
51 skstd::unique_ptr<Moveable, void(*)(Moveable*)> u(nullptr, deleter<Movea
ble>); | 52 skstd::unique_ptr<Moveable, void(*)(Moveable*)> u(nullptr, deleter<Movea
ble>); |
52 static_assert(sizeof(u) == sizeof(BigUniquePtr), WEIRD_SIZE); | 53 static_assert(sizeof(u) == sizeof(BigUniquePtr), WEIRD_SIZE); |
53 | 54 |
54 auto u2 = skstd::move(u); | 55 auto u2 = std::move(u); |
55 static_assert(sizeof(u2) == sizeof(BigUniquePtr), WEIRD_SIZE); | 56 static_assert(sizeof(u2) == sizeof(BigUniquePtr), WEIRD_SIZE); |
56 } | 57 } |
57 | 58 |
58 { | 59 { |
59 skstd::unique_ptr<Moveable, void(*)(Moveable*)> u(nullptr, [](Moveable*
m){ deleter(m); }); | 60 skstd::unique_ptr<Moveable, void(*)(Moveable*)> u(nullptr, [](Moveable*
m){ deleter(m); }); |
60 static_assert(sizeof(u) == sizeof(BigUniquePtr), WEIRD_SIZE); | 61 static_assert(sizeof(u) == sizeof(BigUniquePtr), WEIRD_SIZE); |
61 | 62 |
62 auto u2 = skstd::move(u); | 63 auto u2 = std::move(u); |
63 static_assert(sizeof(u2) == sizeof(BigUniquePtr), WEIRD_SIZE); | 64 static_assert(sizeof(u2) == sizeof(BigUniquePtr), WEIRD_SIZE); |
64 } | 65 } |
65 | 66 |
66 { | 67 { |
67 auto d = [](Moveable* m){ deleter(m); }; | 68 auto d = [](Moveable* m){ deleter(m); }; |
68 skstd::unique_ptr<Moveable, decltype(d)> u(nullptr, d); | 69 skstd::unique_ptr<Moveable, decltype(d)> u(nullptr, d); |
69 static_assert(sizeof(u) == sizeof(SmallUniquePtr), TOO_BIG); | 70 static_assert(sizeof(u) == sizeof(SmallUniquePtr), TOO_BIG); |
70 | 71 |
71 auto u2 = skstd::move(u); | 72 auto u2 = std::move(u); |
72 static_assert(sizeof(u2) == sizeof(SmallUniquePtr), TOO_BIG); | 73 static_assert(sizeof(u2) == sizeof(SmallUniquePtr), TOO_BIG); |
73 } | 74 } |
74 | 75 |
75 { | 76 { |
76 skstd::unique_ptr<Moveable, Deleter<Moveable>> u(nullptr, Deleter<Moveab
le>()); | 77 skstd::unique_ptr<Moveable, Deleter<Moveable>> u(nullptr, Deleter<Moveab
le>()); |
77 static_assert(sizeof(u) == sizeof(SmallUniquePtr), TOO_BIG); | 78 static_assert(sizeof(u) == sizeof(SmallUniquePtr), TOO_BIG); |
78 | 79 |
79 auto u2 = skstd::move(u); | 80 auto u2 = std::move(u); |
80 static_assert(sizeof(u2) == sizeof(SmallUniquePtr), TOO_BIG); | 81 static_assert(sizeof(u2) == sizeof(SmallUniquePtr), TOO_BIG); |
81 } | 82 } |
82 | 83 |
83 { | 84 { |
84 skstd::unique_ptr<Moveable, Deleter<Moveable>> u(new Moveable(), Deleter
<Moveable>()); | 85 skstd::unique_ptr<Moveable, Deleter<Moveable>> u(new Moveable(), Deleter
<Moveable>()); |
85 static_assert(sizeof(u) == sizeof(SmallUniquePtr), TOO_BIG); | 86 static_assert(sizeof(u) == sizeof(SmallUniquePtr), TOO_BIG); |
86 | 87 |
87 auto u2 = skstd::move(u); | 88 auto u2 = std::move(u); |
88 static_assert(sizeof(u2) == sizeof(SmallUniquePtr), TOO_BIG); | 89 static_assert(sizeof(u2) == sizeof(SmallUniquePtr), TOO_BIG); |
89 } | 90 } |
90 | 91 |
91 { | 92 { |
92 skstd::unique_ptr<const void, Deleter<const void>> u(new Moveable(), Del
eter<const void>()); | 93 skstd::unique_ptr<const void, Deleter<const void>> u(new Moveable(), Del
eter<const void>()); |
93 static_assert(sizeof(u) == sizeof(SmallUniquePtr), TOO_BIG); | 94 static_assert(sizeof(u) == sizeof(SmallUniquePtr), TOO_BIG); |
94 | 95 |
95 auto u2 = skstd::move(u); | 96 auto u2 = std::move(u); |
96 static_assert(sizeof(u2) == sizeof(SmallUniquePtr), TOO_BIG); | 97 static_assert(sizeof(u2) == sizeof(SmallUniquePtr), TOO_BIG); |
97 } | 98 } |
98 } | 99 } |
OLD | NEW |