Allow conversion from StringPiece to StringPiece
authorSarang Masti <mssarang@fb.com>
Sat, 20 Dec 2014 00:44:37 +0000 (16:44 -0800)
committerDave Watson <davejwatson@fb.com>
Mon, 29 Dec 2014 18:40:02 +0000 (10:40 -0800)
Summary: Allow conversion from folly::StringPiece to folly::StringPiece

Test Plan: - fbconfig -r folly && fbmake runtests

Reviewed By: mpawlowski@fb.com

Subscribers: folly-diffs@

FB internal diff: D1752609

Signature: t1:1752609:1419037172:04846f658901306b53fb60c9eafbdf0f4d4d7005

folly/Conv.h

index c90b4c03144413c3fd90d2faa6191d506c57b5d3..def3d872b0e6541ffd75c90bfc86c2c038bb8202 100644 (file)
@@ -820,14 +820,15 @@ template <class De, class Ts>
 void toAppendDelimFit(const De&, const Ts&) {}
 
 /**
- * to<SomeString>(SomeString str) returns itself. As both std::string and
- * folly::fbstring use Copy-on-Write, it's much more efficient by
- * avoiding copying the underlying char array.
+ * to<SomeString>(SomeString str) or to<StringPiece>(StringPiece str) returns
+ * itself. As both std::string and folly::fbstring use Copy-on-Write, it's much
+ * more efficient by avoiding copying the underlying char array.
  */
 template <class Tgt, class Src>
 typename std::enable_if<
-  IsSomeString<Tgt>::value && std::is_same<Tgt, Src>::value,
-  Tgt>::type
+  (IsSomeString<Tgt>::value
+   || std::is_same<Tgt, folly::StringPiece>::value)
+  && std::is_same<Tgt, Src>::value, Tgt>::type
 to(const Src & value) {
   return value;
 }