Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(317)

Unified Diff: base/optional.h

Issue 2109063006: Add stream logging support for base::Optional (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/optional.h
diff --git a/base/optional.h b/base/optional.h
index b468964ae339fbead38f769dd315ff39a008d054..2e322dee6d785e6caca8740abb4f2bc44f468176 100644
--- a/base/optional.h
+++ b/base/optional.h
@@ -5,6 +5,7 @@
#ifndef BASE_OPTIONAL_H_
#define BASE_OPTIONAL_H_
+#include <ostream>
#include <type_traits>
#include "base/logging.h"
@@ -436,6 +437,16 @@ constexpr Optional<typename std::decay<T>::type> make_optional(T&& value) {
return Optional<typename std::decay<T>::type>(std::forward<T>(value));
}
+// For logging use only.
+template <class T>
+std::ostream& operator<<(std::ostream& os, const Optional<T>& opt) {
+ if (opt)
+ os << opt.value();
+ else
+ os << "(unset)";
+ return os;
+}
+
template <class T>
void swap(Optional<T>& lhs, Optional<T>& rhs) {
lhs.swap(rhs);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698