From: Sean Cannella Date: Wed, 28 Jan 2015 16:47:51 +0000 (-0800) Subject: Fix Conv.h compilation on Android X-Git-Tag: v0.23.0~16 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=5d8f3bcea827a44f64ce2b800427f4ee611a27cf;p=folly.git 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 --- diff --git a/folly/Conv.h b/folly/Conv.h index 31902c73..f2957125 100644 --- a/folly/Conv.h +++ b/folly/Conv.h @@ -46,6 +46,13 @@ #define FOLLY_RANGE_CHECK_STRINGIZE(x) #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) \ ((condition) ? (void)0 : throw std::range_error( \ (std::string(__FILE__ "(" FOLLY_RANGE_CHECK_STRINGIZE2(__LINE__) "): ") \ @@ -95,15 +102,15 @@ to(const Src & value) { < std::numeric_limits::max()) { FOLLY_RANGE_CHECK( (!greater_than::max()>(value)), - "Overflow", std::to_string(value) - ); + "Overflow", + FOLLY_RANGE_CHECK_TO_STRING(value)); } /* static */ if (std::is_signed::value && (!std::is_signed::value || sizeof(Src) > sizeof(Tgt))) { FOLLY_RANGE_CHECK( (!less_than::min()>(value)), - "Negative overflow", std::to_string(value) - ); + "Negative overflow", + FOLLY_RANGE_CHECK_TO_STRING(value)); } return static_cast(value); } @@ -122,9 +129,11 @@ to(const Src & value) { /* static */ if (std::numeric_limits::max() < std::numeric_limits::max()) { FOLLY_RANGE_CHECK(value <= std::numeric_limits::max(), - "Overflow", std::to_string(value)); + "Overflow", + FOLLY_RANGE_CHECK_TO_STRING(value)); FOLLY_RANGE_CHECK(value >= -std::numeric_limits::max(), - "Negative overflow", std::to_string(value)); + "Negative overflow", + FOLLY_RANGE_CHECK_TO_STRING(value)); } return boost::implicit_cast(value); }