From: Yedidya Feldblum Date: Wed, 27 Jan 2016 07:18:09 +0000 (-0800) Subject: Extract endianness checks into Portability.h X-Git-Tag: deprecate-dynamic-initializer~139 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=ddce90870c1e7bc6dc74ea65077001cfd987b68d;p=folly.git Extract endianness checks into Portability.h Summary: [Folly] Extract endianness checks into Portability.h. Reviewed By: fugalh Differential Revision: D2857924 fb-gh-sync-id: 23ecd2a3cad661024acb62769cd85df394786c59 --- diff --git a/folly/FBString.h b/folly/FBString.h index d26b961d..2acaaf79 100644 --- a/folly/FBString.h +++ b/folly/FBString.h @@ -289,13 +289,6 @@ private: * to extract capacity/category. */ template class fbstring_core { -protected: - static constexpr bool kIsLittleEndian = - __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__; - static constexpr bool kIsBigEndian = - __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__; - static_assert( - kIsLittleEndian || kIsBigEndian, "unable to identify endianness"); public: fbstring_core() noexcept { reset(); } diff --git a/folly/Portability.h b/folly/Portability.h index 63318a2c..9784ef2e 100644 --- a/folly/Portability.h +++ b/folly/Portability.h @@ -305,6 +305,21 @@ typedef SSIZE_T ssize_t; #endif +// Endianness +namespace folly { +#ifdef _MSC_VER +// It's MSVC, so we just have to guess ... and allow an override +#ifdef FOLLY_ENDIAN_BE +constexpr auto kIsLittleEndian = false; +#else +constexpr auto kIsLittleEndian = true; +#endif +#else +constexpr auto kIsLittleEndian = __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__; +#endif +constexpr auto kIsBigEndian = !kIsLittleEndian; +} + #ifndef FOLLY_SSE # if defined(__SSE4_2__) # define FOLLY_SSE 4