Use folly::Expected to implement folly::tryTo, a non-throwing variant of folly::to
authorEric Niebler <eniebler@fb.com>
Tue, 16 Aug 2016 23:06:57 +0000 (16:06 -0700)
committerFacebook Github Bot <facebook-github-bot-bot@fb.com>
Tue, 16 Aug 2016 23:08:26 +0000 (16:08 -0700)
commit4da4f3311fa21190626b6a50eefde436028415c8
tree0cb3c734619b2093c47fe7123b9a4fa4d7d08024
parent5d242d14dcca79124ed477b246730353f6f76dc2
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: D3720512

fbshipit-source-id: dadb8db1b7d7ad8d3e80c1cc69c0480169f9217a
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