aboutsummaryrefslogtreecommitdiff
path: root/third_party/chromium/base/logging.h
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/chromium/base/logging.h')
-rw-r--r--third_party/chromium/base/logging.h33
1 files changed, 32 insertions, 1 deletions
diff --git a/third_party/chromium/base/logging.h b/third_party/chromium/base/logging.h
index 1290bfe..3b89853 100644
--- a/third_party/chromium/base/logging.h
+++ b/third_party/chromium/base/logging.h
@@ -12,9 +12,12 @@
#include <sstream>
#include <string>
#include <typeinfo>
+#include <type_traits>
+#include <utility>
#include "base/base_export.h"
#include "base/macros.h"
+#include "base/template_util.h"
#include "build/build_config.h"
//
@@ -421,6 +424,30 @@ class CheckOpResult {
#endif
+// This formats a value for a failing CHECK_XX statement. Ordinarily,
+// it uses the definition for operator<<, with a few special cases below.
+template <typename T>
+inline typename std::enable_if<
+ base::internal::SupportsOstreamOperator<const T&>::value,
+ void>::type
+MakeCheckOpValueString(std::ostream* os, const T& v) {
+ (*os) << v;
+}
+
+// We need overloads for enums that don't support operator<<.
+// (i.e. scoped enums where no operator<< overload was declared).
+template <typename T>
+inline typename std::enable_if<
+ !base::internal::SupportsOstreamOperator<const T&>::value &&
+ std::is_enum<T>::value,
+ void>::type
+MakeCheckOpValueString(std::ostream* os, const T& v) {
+ (*os) << static_cast<typename base::underlying_type<T>::type>(v);
+}
+
+// We need an explicit overload for std::nullptr_t.
+BASE_EXPORT void MakeCheckOpValueString(std::ostream* os, std::nullptr_t p);
+
// Build the error message string. This is separate from the "Impl"
// function template because it is not performance critical and so can
// be out of line, while the "Impl" code should be inline. Caller
@@ -428,7 +455,11 @@ class CheckOpResult {
template<class t1, class t2>
std::string* MakeCheckOpString(const t1& v1, const t2& v2, const char* names) {
std::ostringstream ss;
- ss << names << " (" << v1 << " vs. " << v2 << ")";
+ ss << names << " (";
+ MakeCheckOpValueString(&ss, v1);
+ ss << " vs. ";
+ MakeCheckOpValueString(&ss, v2);
+ ss << ")";
std::string* msg = new std::string(ss.str());
return msg;
}