Support numeric types as targets for folly::split
authorMarcus Holland-Moritz <mhx@fb.com>
Mon, 10 Mar 2014 18:35:00 +0000 (11:35 -0700)
committerDave Watson <davejwatson@fb.com>
Mon, 10 Mar 2014 20:51:17 +0000 (13:51 -0700)
commit9f95e046d5efc40ca366cf2423e09d13fb8590e3
treec411f6ef69e846a222b06cf8af371e3080879ff5
parent86fd9acf3fd36e7c54b62bf476dd905803bd7d8d
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
folly/String-inl.h
folly/String.h
folly/test/StringTest.cpp