Disabling conversion with contained value for Optional
[folly.git] / folly / Format-inl.h
index bba7be85ed588e310412f70054f7e1c407c3dfb0..70672d476ebedc710194fe14abdb67c239e8984b 100644 (file)
@@ -18,6 +18,8 @@
 #error This file may only be included from Format.h.
 #endif
 
+#include "folly/Traits.h"
+
 namespace folly {
 
 namespace detail {
@@ -45,7 +47,7 @@ size_t uintToHex(char* buffer, size_t bufLen, Uint v,
                  const char (&repr)[256][2]) {
   // 'v >>= 7, v >>= 1' is no more than a work around to get rid of shift size
   // warning when Uint = uint8_t (it's false as v >= 256 implies sizeof(v) > 1).
-  for (; v >= 256; v >>= 7, v >>= 1) {
+  for (; !less_than<unsigned, 256>(v); v >>= 7, v >>= 1) {
     auto b = v & 0xff;
     bufLen -= 2;
     buffer[bufLen] = repr[b][0];
@@ -89,7 +91,7 @@ size_t uintToOctal(char* buffer, size_t bufLen, Uint v) {
   auto& repr = formatOctal;
   // 'v >>= 7, v >>= 2' is no more than a work around to get rid of shift size
   // warning when Uint = uint8_t (it's false as v >= 512 implies sizeof(v) > 1).
-  for (; v >= 512; v >>= 7, v >>= 2) {
+  for (; !less_than<unsigned, 512>(v); v >>= 7, v >>= 2) {
     auto b = v & 0x1ff;
     bufLen -= 3;
     buffer[bufLen] = repr[b][0];
@@ -377,7 +379,7 @@ class FormatValue<
     UT uval;
     char sign;
     if (std::is_signed<T>::value) {
-      if (val_ < 0) {
+      if (folly::is_negative(val_)) {
         uval = static_cast<UT>(-val_);
         sign = '-';
       } else {
@@ -562,8 +564,6 @@ class FormatValue<double> {
       arg.precision = 6;
     }
 
-    bool done = false;
-
     // 2+: for null terminator and optional sign shenanigans.
     char buf[2 + std::max({
         (2 + DoubleToStringConverter::kMaxFixedDigitsBeforePoint +