Disable implicit conversions from std::string for non-char* Range
authorGiuseppe Ottaviano <ott@fb.com>
Thu, 18 Dec 2014 02:19:00 +0000 (18:19 -0800)
committerJoelMarcey <joelm@fb.com>
Thu, 18 Dec 2014 20:29:41 +0000 (12:29 -0800)
commitc1a244da6daacd948fdbda1d0770372623101fb7
tree6a4bb0e245b2a9434b9d2e15f6aa4cbb8a7ea426
parentaf581fbe42659d1ca51a05fde6743ec83998f11b
Disable implicit conversions from std::string for non-char* Range

Summary:
`Range<Iter>` has an implicit constructors from strings for any
`Iter`, however such constructors are invalid (compilation fails)
if `Iter` is not `[const] char *`.

This can be an issue for overload resolution: for example

struct IsString {
bool operator()(folly::Range<int*>) { return false; }
bool operator()(folly::StringPiece) { return true; }
};

IsString()(std::string());

fails to compile because the overload is ambiguous, even if the
conversion to `ByteRange` is invalid.

This patch disables all the invalid constructors from
`[const] char*`, `std::string`, and `fbstring`.

Test Plan:
fbconfig -r folly && fbmake runtests_opt

Reviewed By: philipp@fb.com

Subscribers: folly-diffs@

FB internal diff: D1746899

Signature: t1:1746899:1418868361:50784c4993df0bd96eeb62c09c659d5e53964d9b
folly/Range.h
folly/test/RangeTest.cpp