From 53fc7e17633c19b4991462890d4bbb9a7d7cb1a7 Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Wed, 1 Nov 2017 05:14:35 +0000 Subject: [PATCH] Reformat. llvm-svn: 317078 --- llvm/include/llvm/ADT/Optional.h | 64 ++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/llvm/include/llvm/ADT/Optional.h b/llvm/include/llvm/ADT/Optional.h index b782d9da17ac..2811d5c1e21b 100644 --- a/llvm/include/llvm/ADT/Optional.h +++ b/llvm/include/llvm/ADT/Optional.h @@ -27,8 +27,7 @@ namespace llvm { -template -class Optional { +template class Optional { AlignedCharArrayUnion storage; bool hasVal = false; @@ -38,18 +37,14 @@ public: Optional(NoneType) {} explicit Optional() {} - Optional(const T &y) : hasVal(true) { - new (storage.buffer) T(y); - } + Optional(const T &y) : hasVal(true) { new (storage.buffer) T(y); } Optional(const Optional &O) : hasVal(O.hasVal) { if (hasVal) new (storage.buffer) T(*O); } - Optional(T &&y) : hasVal(true) { - new (storage.buffer) T(std::forward(y)); - } + Optional(T &&y) : hasVal(true) { new (storage.buffer) T(std::forward(y)); } Optional(Optional &&O) : hasVal(O) { if (O) { @@ -58,9 +53,7 @@ public: } } - ~Optional() { - reset(); - } + ~Optional() { reset(); } Optional &operator=(T &&y) { if (hasVal) @@ -83,14 +76,13 @@ public: } /// Create a new object by constructing it in place with the given arguments. - template - void emplace(ArgTypes &&...Args) { + template void emplace(ArgTypes &&... Args) { reset(); hasVal = true; new (storage.buffer) T(std::forward(Args)...); } - static inline Optional create(const T* y) { + static inline Optional create(const T *y) { return y ? Optional(*y) : Optional(); } @@ -124,17 +116,35 @@ public: } } - const T* getPointer() const { assert(hasVal); return reinterpret_cast(storage.buffer); } - T* getPointer() { assert(hasVal); return reinterpret_cast(storage.buffer); } - const T& getValue() const LLVM_LVALUE_FUNCTION { assert(hasVal); return *getPointer(); } - T& getValue() LLVM_LVALUE_FUNCTION { assert(hasVal); return *getPointer(); } + const T *getPointer() const { + assert(hasVal); + return reinterpret_cast(storage.buffer); + } + T *getPointer() { + assert(hasVal); + return reinterpret_cast(storage.buffer); + } + const T &getValue() const LLVM_LVALUE_FUNCTION { + assert(hasVal); + return *getPointer(); + } + T &getValue() LLVM_LVALUE_FUNCTION { + assert(hasVal); + return *getPointer(); + } explicit operator bool() const { return hasVal; } bool hasValue() const { return hasVal; } - const T* operator->() const { return getPointer(); } - T* operator->() { return getPointer(); } - const T& operator*() const LLVM_LVALUE_FUNCTION { assert(hasVal); return *getPointer(); } - T& operator*() LLVM_LVALUE_FUNCTION { assert(hasVal); return *getPointer(); } + const T *operator->() const { return getPointer(); } + T *operator->() { return getPointer(); } + const T &operator*() const LLVM_LVALUE_FUNCTION { + assert(hasVal); + return *getPointer(); + } + T &operator*() LLVM_LVALUE_FUNCTION { + assert(hasVal); + return *getPointer(); + } template constexpr T getValueOr(U &&value) const LLVM_LVALUE_FUNCTION { @@ -142,8 +152,14 @@ public: } #if LLVM_HAS_RVALUE_REFERENCE_THIS - T&& getValue() && { assert(hasVal); return std::move(*getPointer()); } - T&& operator*() && { assert(hasVal); return std::move(*getPointer()); } + T &&getValue() && { + assert(hasVal); + return std::move(*getPointer()); + } + T &&operator*() && { + assert(hasVal); + return std::move(*getPointer()); + } template T getValueOr(U &&value) && {