| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 HEADLESS_PUBLIC_UTIL_MAYBE_H_ | 5 #ifndef HEADLESS_PUBLIC_UTIL_MAYBE_H_ |
| 6 #define HEADLESS_PUBLIC_UTIL_MAYBE_H_ | 6 #define HEADLESS_PUBLIC_UTIL_MAYBE_H_ |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 | 12 |
| 13 namespace headless { | 13 namespace headless { |
| 14 | 14 |
| 15 // A simple Maybe which may or may not have a value. Based on v8::Maybe. | 15 // A simple Maybe which may or may not have a value. Based on v8::Maybe. |
| 16 // TODO(skyostil): Replace this with base::Optional once it is available. |
| 16 template <typename T> | 17 template <typename T> |
| 17 class Maybe { | 18 class Maybe { |
| 18 public: | 19 public: |
| 19 Maybe() : has_value_(false) {} | 20 Maybe() : has_value_(false) {} |
| 20 | 21 |
| 21 bool IsNothing() const { return !has_value_; } | 22 bool IsNothing() const { return !has_value_; } |
| 22 bool IsJust() const { return has_value_; } | 23 bool IsJust() const { return has_value_; } |
| 23 | 24 |
| 24 // Will crash if the Maybe<> is nothing. | 25 // Will crash if the Maybe<> is nothing. |
| 25 T& FromJust() { | 26 T& FromJust() { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 } | 84 } |
| 84 | 85 |
| 85 template <class T> | 86 template <class T> |
| 86 Maybe<typename std::remove_reference<T>::type> Just(T&& t) { | 87 Maybe<typename std::remove_reference<T>::type> Just(T&& t) { |
| 87 return Maybe<typename std::remove_reference<T>::type>(std::move(t)); | 88 return Maybe<typename std::remove_reference<T>::type>(std::move(t)); |
| 88 } | 89 } |
| 89 | 90 |
| 90 } // namespace headless | 91 } // namespace headless |
| 91 | 92 |
| 92 #endif // HEADLESS_PUBLIC_UTIL_MAYBE_H_ | 93 #endif // HEADLESS_PUBLIC_UTIL_MAYBE_H_ |
| OLD | NEW |