constexpr estimateSpaceNeeded for string literals. v2017.10.16.00
authorAndrew Krieger <andrew.krieger@oculus.com>
Mon, 16 Oct 2017 04:30:56 +0000 (21:30 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Mon, 16 Oct 2017 04:36:02 +0000 (21:36 -0700)
Summary:
Partially inspired by WillerZ's investigation into faster compiling
StringPiece work, I thought this would be an easy drop in that short
circuits some compilation logic (or possibly is strictly better, since the
StringPiece conversion method isn't constexpr).

Reviewed By: yfeldblum

Differential Revision: D6059537

fbshipit-source-id: 072f56e58aa47db10b54825cac8a05dc035b295c

folly/Conv.h

index be0d3d0dafa994695cc64ac43943a0a3e60a064d..ce30765c6f8d3bac9e8da6129d2ba6601eaeeed9 100644 (file)
@@ -408,6 +408,11 @@ estimateSpaceNeeded(T) {
   return 1;
 }
 
+template <size_t N>
+constexpr size_t estimateSpaceNeeded(const char (&)[N]) {
+  return N;
+}
+
 /**
  * Everything implicitly convertible to const char* gets appended.
  */