| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_ |
| 7 | 7 |
| 8 #include <cstddef> | 8 #include <cstddef> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <new> | 10 #include <new> |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 98 |
| 99 MOJO_MOVE_ONLY_TYPE(StructPtr); | 99 MOJO_MOVE_ONLY_TYPE(StructPtr); |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 // Designed to be used when Struct is small and copyable. Unions are always | 102 // Designed to be used when Struct is small and copyable. Unions are always |
| 103 // InlinedStructPtr in practice. | 103 // InlinedStructPtr in practice. |
| 104 template <typename Struct> | 104 template <typename Struct> |
| 105 class InlinedStructPtr { | 105 class InlinedStructPtr { |
| 106 public: | 106 public: |
| 107 InlinedStructPtr() : is_null_(true) {} | 107 InlinedStructPtr() : is_null_(true) {} |
| 108 InlinedStructPtr(decltype(nullptr)) : is_null_(true) {} | 108 InlinedStructPtr(std::nullptr_t) : is_null_(true) {} |
| 109 | 109 |
| 110 ~InlinedStructPtr() {} | 110 ~InlinedStructPtr() {} |
| 111 | 111 |
| 112 InlinedStructPtr& operator=(decltype(nullptr)) { | 112 InlinedStructPtr& operator=(std::nullptr_t) { |
| 113 reset(); | 113 reset(); |
| 114 return *this; | 114 return *this; |
| 115 } | 115 } |
| 116 | 116 |
| 117 InlinedStructPtr(InlinedStructPtr&& other) : is_null_(true) { Take(&other); } | 117 InlinedStructPtr(InlinedStructPtr&& other) : is_null_(true) { Take(&other); } |
| 118 InlinedStructPtr& operator=(InlinedStructPtr&& other) { | 118 InlinedStructPtr& operator=(InlinedStructPtr&& other) { |
| 119 Take(&other); | 119 Take(&other); |
| 120 return *this; | 120 return *this; |
| 121 } | 121 } |
| 122 | 122 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 171 |
| 172 mutable Struct value_; | 172 mutable Struct value_; |
| 173 bool is_null_; | 173 bool is_null_; |
| 174 | 174 |
| 175 MOJO_MOVE_ONLY_TYPE(InlinedStructPtr); | 175 MOJO_MOVE_ONLY_TYPE(InlinedStructPtr); |
| 176 }; | 176 }; |
| 177 | 177 |
| 178 } // namespace mojo | 178 } // namespace mojo |
| 179 | 179 |
| 180 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_ | 180 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_ |
| OLD | NEW |