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

Side by Side Diff: base/logging.h

Issue 2515283002: logging: Provide a specific MakeCheckOpValueString overload for functions (Closed)
Patch Set: Use actual member functions Created 4 years 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 unified diff | Download patch
« no previous file with comments | « no previous file | base/logging_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 BASE_LOGGING_H_ 5 #ifndef BASE_LOGGING_H_
6 #define BASE_LOGGING_H_ 6 #define BASE_LOGGING_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <cassert> 10 #include <cassert>
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 ; \ 520 ; \
521 else \ 521 else \
522 ::logging::LogMessage(__FILE__, __LINE__, true_if_passed.message()).stream() 522 ::logging::LogMessage(__FILE__, __LINE__, true_if_passed.message()).stream()
523 523
524 #endif // !(OFFICIAL_BUILD && NDEBUG) 524 #endif // !(OFFICIAL_BUILD && NDEBUG)
525 525
526 // This formats a value for a failing CHECK_XX statement. Ordinarily, 526 // This formats a value for a failing CHECK_XX statement. Ordinarily,
527 // it uses the definition for operator<<, with a few special cases below. 527 // it uses the definition for operator<<, with a few special cases below.
528 template <typename T> 528 template <typename T>
529 inline typename std::enable_if< 529 inline typename std::enable_if<
530 base::internal::SupportsOstreamOperator<const T&>::value, 530 base::internal::SupportsOstreamOperator<const T&>::value &&
531 !std::is_function<typename std::remove_pointer<T>::type>::value,
531 void>::type 532 void>::type
532 MakeCheckOpValueString(std::ostream* os, const T& v) { 533 MakeCheckOpValueString(std::ostream* os, const T& v) {
533 (*os) << v; 534 (*os) << v;
534 } 535 }
535 536
537 // Provide an overload for functions and function pointers. Function pointers
538 // don't implicitly convert to void* but do implicitly convert to bool, so
539 // without this function pointers are always printed as 1 or 0. (MSVC isn't
540 // standards-conforming here and converts function pointers to regular
541 // pointers, so this is a no-op for MSVC.)
542 template <typename T>
543 inline typename std::enable_if<
544 std::is_function<typename std::remove_pointer<T>::type>::value,
545 void>::type
546 MakeCheckOpValueString(std::ostream* os, const T& v) {
547 (*os) << reinterpret_cast<const void*>(v);
548 }
549
536 // We need overloads for enums that don't support operator<<. 550 // We need overloads for enums that don't support operator<<.
537 // (i.e. scoped enums where no operator<< overload was declared). 551 // (i.e. scoped enums where no operator<< overload was declared).
538 template <typename T> 552 template <typename T>
539 inline typename std::enable_if< 553 inline typename std::enable_if<
540 !base::internal::SupportsOstreamOperator<const T&>::value && 554 !base::internal::SupportsOstreamOperator<const T&>::value &&
541 std::is_enum<T>::value, 555 std::is_enum<T>::value,
542 void>::type 556 void>::type
543 MakeCheckOpValueString(std::ostream* os, const T& v) { 557 MakeCheckOpValueString(std::ostream* os, const T& v) {
544 (*os) << static_cast<typename base::underlying_type<T>::type>(v); 558 (*os) << static_cast<typename base::underlying_type<T>::type>(v);
545 } 559 }
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 #elif NOTIMPLEMENTED_POLICY == 5 1002 #elif NOTIMPLEMENTED_POLICY == 5
989 #define NOTIMPLEMENTED() do {\ 1003 #define NOTIMPLEMENTED() do {\
990 static bool logged_once = false;\ 1004 static bool logged_once = false;\
991 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ 1005 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\
992 logged_once = true;\ 1006 logged_once = true;\
993 } while(0);\ 1007 } while(0);\
994 EAT_STREAM_PARAMETERS 1008 EAT_STREAM_PARAMETERS
995 #endif 1009 #endif
996 1010
997 #endif // BASE_LOGGING_H_ 1011 #endif // BASE_LOGGING_H_
OLDNEW
« no previous file with comments | « no previous file | base/logging_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698