| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 Optional_h | 5 #ifndef Optional_h |
| 6 #define Optional_h | 6 #define Optional_h |
| 7 | 7 |
| 8 #include "wtf/Alignment.h" | 8 #include "wtf/Alignment.h" |
| 9 #include "wtf/Allocator.h" | 9 #include "wtf/Allocator.h" |
| 10 #include "wtf/Assertions.h" | 10 #include "wtf/Assertions.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 operator UnspecifiedBoolType() const { return m_ptr ? &Optional::m_ptr : nul
lptr; } | 47 operator UnspecifiedBoolType() const { return m_ptr ? &Optional::m_ptr : nul
lptr; } |
| 48 | 48 |
| 49 T& operator*() { ASSERT_WITH_SECURITY_IMPLICATION(m_ptr); return *m_ptr; } | 49 T& operator*() { ASSERT_WITH_SECURITY_IMPLICATION(m_ptr); return *m_ptr; } |
| 50 const T& operator*() const { ASSERT_WITH_SECURITY_IMPLICATION(m_ptr); return
*m_ptr; } | 50 const T& operator*() const { ASSERT_WITH_SECURITY_IMPLICATION(m_ptr); return
*m_ptr; } |
| 51 T* operator->() { ASSERT_WITH_SECURITY_IMPLICATION(m_ptr); return m_ptr; } | 51 T* operator->() { ASSERT_WITH_SECURITY_IMPLICATION(m_ptr); return m_ptr; } |
| 52 const T* operator->() const { ASSERT_WITH_SECURITY_IMPLICATION(m_ptr); retur
n m_ptr; } | 52 const T* operator->() const { ASSERT_WITH_SECURITY_IMPLICATION(m_ptr); retur
n m_ptr; } |
| 53 | 53 |
| 54 template <typename... Args> | 54 template <typename... Args> |
| 55 void emplace(Args&&... args) | 55 void emplace(Args&&... args) |
| 56 { | 56 { |
| 57 CHECK(!m_ptr); | 57 RELEASE_ASSERT(!m_ptr); |
| 58 m_ptr = reinterpret_cast_ptr<T*>(&m_storage.buffer); | 58 m_ptr = reinterpret_cast_ptr<T*>(&m_storage.buffer); |
| 59 new (m_ptr) T(std::forward<Args>(args)...); | 59 new (m_ptr) T(std::forward<Args>(args)...); |
| 60 } | 60 } |
| 61 | 61 |
| 62 private: | 62 private: |
| 63 T* m_ptr; | 63 T* m_ptr; |
| 64 AlignedBuffer<sizeof(T), WTF_ALIGN_OF(T)> m_storage; | 64 AlignedBuffer<sizeof(T), WTF_ALIGN_OF(T)> m_storage; |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 } // namespace WTF | 67 } // namespace WTF |
| 68 | 68 |
| 69 using WTF::Optional; | 69 using WTF::Optional; |
| 70 | 70 |
| 71 #endif // Optional_h | 71 #endif // Optional_h |
| OLD | NEW |