logging: fix compiler compatibility for one more constexpr function
[folly.git] / folly / experimental / logging / LogLevel.h
index 7ce01e66d0dca72da6aefb36b16c0484e537a5e4..a3e0e34abf71c6cd8dbba0da8af076e9b916576d 100644 (file)
@@ -84,12 +84,11 @@ enum class LogLevel : uint32_t {
  * adjusted log level values.
  */
 inline constexpr LogLevel operator+(LogLevel level, uint32_t value) {
-  auto newValue = static_cast<uint32_t>(level) + value;
   // Cap the result at LogLevel::MAX_LEVEL
-  if (newValue > static_cast<uint32_t>(LogLevel::MAX_LEVEL)) {
-    return LogLevel::MAX_LEVEL;
-  }
-  return static_cast<LogLevel>(newValue);
+  return ((static_cast<uint32_t>(level) + value) >
+          static_cast<uint32_t>(LogLevel::MAX_LEVEL))
+      ? LogLevel::MAX_LEVEL
+      : static_cast<LogLevel>(static_cast<uint32_t>(level) + value);
 }
 inline LogLevel& operator+=(LogLevel& level, uint32_t value) {
   level = level + value;
@@ -122,10 +121,7 @@ std::ostream& operator<<(std::ostream& os, LogLevel level);
  * Returns true if and only if a LogLevel is fatal.
  */
 inline constexpr bool isLogLevelFatal(LogLevel level) {
-  if (folly::kIsDebug) {
-    return level >= LogLevel::DFATAL;
-  } else {
-    return level >= LogLevel::FATAL;
-  }
+  return folly::kIsDebug ? (level >= LogLevel::DFATAL)
+                         : (level >= LogLevel::FATAL);
 }
 }