Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_BASE_OPTIONAL_H_ | 11 #ifndef WEBRTC_BASE_OPTIONAL_H_ |
| 12 #define WEBRTC_BASE_OPTIONAL_H_ | 12 #define WEBRTC_BASE_OPTIONAL_H_ |
| 13 | 13 |
| 14 #include <algorithm> | 14 #include <algorithm> |
| 15 #include <utility> | 15 #include <utility> |
| 16 | 16 #include <ostream> |
| 17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
| 18 | 18 |
| 19 namespace rtc { | 19 namespace rtc { |
| 20 | 20 |
| 21 // Simple std::experimental::optional-wannabe. It either contains a T or not. | 21 // Simple std::experimental::optional-wannabe. It either contains a T or not. |
| 22 // In order to keep the implementation simple and portable, this implementation | 22 // In order to keep the implementation simple and portable, this implementation |
| 23 // actually contains a (default-constructed) T even when it supposedly doesn't | 23 // actually contains a (default-constructed) T even when it supposedly doesn't |
| 24 // contain a value; use e.g. rtc::scoped_ptr<T> instead if that's too | 24 // contain a value; use e.g. rtc::scoped_ptr<T> instead if that's too |
| 25 // expensive. | 25 // expensive. |
| 26 // | 26 // |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 : m1.has_value_ != m2.has_value_; | 127 : m1.has_value_ != m2.has_value_; |
| 128 } | 128 } |
| 129 | 129 |
| 130 private: | 130 private: |
| 131 // Invariant: Unless *this has been moved from, value_ is default-initialized | 131 // Invariant: Unless *this has been moved from, value_ is default-initialized |
| 132 // (or copied or moved from a default-initialized T) if !has_value_. | 132 // (or copied or moved from a default-initialized T) if !has_value_. |
| 133 T value_; | 133 T value_; |
| 134 bool has_value_; | 134 bool has_value_; |
| 135 }; | 135 }; |
| 136 | 136 |
| 137 // Defines the operator to write Optional<T> to an output stream. Allows for | |
| 138 // simplified logging of optional parameters. | |
| 139 template <typename T> | |
| 140 std::ostream& operator<<(std::ostream& stream, rtc::Optional<T> value) { | |
|
kwiberg-webrtc
2016/03/29 11:30:45
Second argument should be const ref to avoid copyi
skvlad
2016/03/30 19:40:44
Done.
| |
| 141 if (value) { | |
| 142 stream << *value; | |
| 143 } else { | |
| 144 stream << "<not set>"; | |
| 145 } | |
| 146 return stream; | |
| 147 } | |
| 148 | |
| 137 } // namespace rtc | 149 } // namespace rtc |
| 138 | 150 |
| 139 #endif // WEBRTC_BASE_OPTIONAL_H_ | 151 #endif // WEBRTC_BASE_OPTIONAL_H_ |
| OLD | NEW |