Support numeric types as targets for folly::split
Summary:
This extends the fixed version of folly::split to support numeric types
as targets in addition to string pieces. I was almost certain this was
already possible when I recently reviewed some code that did
folly::StringPiece source, target, strFrequency;
int frequency;
if (folly::split('\t', line, source, target, strFrequency) &&
(frequency = folly::to<unsigned int>(strFrequency)) > 0)
and was about to suggest changing the above into:
folly::StringPiece source, target;
int frequency;
if (folly::split('\t', line, source, target, frequency) && frequency > 0)
I double checked and saw that only splitting to string pieces was supported.
In the meantime I came across this pattern again and decided to just make
it work because it's really convenient.
The implementation should be fully backwards compatible.
Test Plan:
- New unit tests
- fbconfig -r folly && fbmake runtests
- Applied to github release, ./configure && make check
Reviewed By: andrei.alexandrescu@fb.com
FB internal diff:
D1187004