Use folly::Expected to implement folly::tryTo, a non-throwing variant of folly::to
authorEric Niebler <eniebler@fb.com>
Mon, 15 Aug 2016 21:03:58 +0000 (14:03 -0700)
committerFacebook Github Bot 5 <facebook-github-bot-5-bot@fb.com>
Mon, 15 Aug 2016 21:08:31 +0000 (14:08 -0700)
commit89cc32931877aa684e1a1f06776f564a49d39eab
tree76f4bd742ed366564ecdc2cd7e812b9b0c48161a
parentae7eed06cfb8d1f9487b51536f4385bb0e82e9df
Use folly::Expected to implement folly::tryTo, a non-throwing variant of folly::to

Summary:
This change adds a non-throwing interface for folly::to<T>: tryTo<T>, which
returns an Expected<T, ConversionCode>.

Here is how the non-throwing interface compares to the regular interface in
terms of performance. On the successful path, there's generally not much
difference between using the throwing and non-throwing interfaces. For the
error path, tryTo<> is about three orders of magnitude faster than to<>.

Reviewed By: mhx

Differential Revision: D3557832

fbshipit-source-id: 25b29834b6fda474a7cdd43a7dea69ff4ee183c8
folly/Conv.cpp
folly/Conv.h
folly/Portability.h
folly/String-inl.h
folly/String.h
folly/docs/Conv.md
folly/test/ConvBenchmark.cpp
folly/test/ConvTest.cpp
folly/test/StringTest.cpp
folly/test/TraitsTest.cpp