Commit 5d8f3bce authored by Sean Cannella's avatar Sean Cannella Committed by woo

Fix Conv.h compilation on Android

Summary:
std::to_string doesn't exist on Android so don't use it.

Facebook: Did a sync to fbandroid and confirmed liger compiles with this fix.

Test Plan: existing tests

Reviewed By: ranjeeth@fb.com

Subscribers: trunkagent, folly-diffs@, shikong, kmdent, fma, pgriess

FB internal diff: D1808037

Signature: t1:1808037:1422410556:d78e0633a1554254b1a1f25bef49a4550a1817c6
parent c4a221ce
...@@ -46,6 +46,13 @@ ...@@ -46,6 +46,13 @@
#define FOLLY_RANGE_CHECK_STRINGIZE(x) #x #define FOLLY_RANGE_CHECK_STRINGIZE(x) #x
#define FOLLY_RANGE_CHECK_STRINGIZE2(x) FOLLY_RANGE_CHECK_STRINGIZE(x) #define FOLLY_RANGE_CHECK_STRINGIZE2(x) FOLLY_RANGE_CHECK_STRINGIZE(x)
// Android doesn't support std::to_string so just use a placeholder there.
#ifdef __ANDROID__
#define FOLLY_RANGE_CHECK_TO_STRING(x) std::string("N/A")
#else
#define FOLLY_RANGE_CHECK_TO_STRING(x) std::to_string(x)
#endif
#define FOLLY_RANGE_CHECK(condition, message, src) \ #define FOLLY_RANGE_CHECK(condition, message, src) \
((condition) ? (void)0 : throw std::range_error( \ ((condition) ? (void)0 : throw std::range_error( \
(std::string(__FILE__ "(" FOLLY_RANGE_CHECK_STRINGIZE2(__LINE__) "): ") \ (std::string(__FILE__ "(" FOLLY_RANGE_CHECK_STRINGIZE2(__LINE__) "): ") \
...@@ -95,15 +102,15 @@ to(const Src & value) { ...@@ -95,15 +102,15 @@ to(const Src & value) {
< std::numeric_limits<Src>::max()) { < std::numeric_limits<Src>::max()) {
FOLLY_RANGE_CHECK( FOLLY_RANGE_CHECK(
(!greater_than<Tgt, std::numeric_limits<Tgt>::max()>(value)), (!greater_than<Tgt, std::numeric_limits<Tgt>::max()>(value)),
"Overflow", std::to_string(value) "Overflow",
); FOLLY_RANGE_CHECK_TO_STRING(value));
} }
/* static */ if (std::is_signed<Src>::value && /* static */ if (std::is_signed<Src>::value &&
(!std::is_signed<Tgt>::value || sizeof(Src) > sizeof(Tgt))) { (!std::is_signed<Tgt>::value || sizeof(Src) > sizeof(Tgt))) {
FOLLY_RANGE_CHECK( FOLLY_RANGE_CHECK(
(!less_than<Tgt, std::numeric_limits<Tgt>::min()>(value)), (!less_than<Tgt, std::numeric_limits<Tgt>::min()>(value)),
"Negative overflow", std::to_string(value) "Negative overflow",
); FOLLY_RANGE_CHECK_TO_STRING(value));
} }
return static_cast<Tgt>(value); return static_cast<Tgt>(value);
} }
...@@ -122,9 +129,11 @@ to(const Src & value) { ...@@ -122,9 +129,11 @@ to(const Src & value) {
/* static */ if (std::numeric_limits<Tgt>::max() < /* static */ if (std::numeric_limits<Tgt>::max() <
std::numeric_limits<Src>::max()) { std::numeric_limits<Src>::max()) {
FOLLY_RANGE_CHECK(value <= std::numeric_limits<Tgt>::max(), FOLLY_RANGE_CHECK(value <= std::numeric_limits<Tgt>::max(),
"Overflow", std::to_string(value)); "Overflow",
FOLLY_RANGE_CHECK_TO_STRING(value));
FOLLY_RANGE_CHECK(value >= -std::numeric_limits<Tgt>::max(), FOLLY_RANGE_CHECK(value >= -std::numeric_limits<Tgt>::max(),
"Negative overflow", std::to_string(value)); "Negative overflow",
FOLLY_RANGE_CHECK_TO_STRING(value));
} }
return boost::implicit_cast<Tgt>(value); return boost::implicit_cast<Tgt>(value);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment