logging: fix compiler compatibility for one more constexpr function
authorAdam Simpkins <simpkins@fb.com>
Wed, 5 Jul 2017 17:48:49 +0000 (10:48 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Wed, 5 Jul 2017 17:50:04 +0000 (10:50 -0700)
Summary:
Update LogLevel's operator+() to consist only of a single return statement.
This is required for pre-C++14 compiler support.

Reviewed By: yfeldblum

Differential Revision: D5368256

fbshipit-source-id: 9ecbcde5edd1d0b3e7580d6263ad926e44908219

folly/experimental/logging/LogLevel.h

index 75f401b..a3e0e34 100644 (file)
@@ -84,12 +84,11 @@ enum class LogLevel : uint32_t {
  * adjusted log level values.
  */
 inline constexpr LogLevel operator+(LogLevel level, uint32_t value) {
  * 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
   // 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;
 }
 inline LogLevel& operator+=(LogLevel& level, uint32_t value) {
   level = level + value;