1
0
mirror of https://github.com/nlohmann/json.git synced 2025-08-07 18:02:57 +03:00

simpler endian detection for older gcc versions

This commit is contained in:
Francois Chabot
2020-02-20 10:19:29 -05:00
parent 770ae6e9da
commit c7282d5b1e
3 changed files with 30 additions and 26 deletions

View File

@@ -24,6 +24,20 @@ namespace nlohmann
{
namespace detail
{
/*!
@brief determine system byte order
@return true if and only if system's byte order is little endian
@note from https://stackoverflow.com/a/1001328/266378
*/
static bool little_endianess(int num = 1) noexcept
{
return *reinterpret_cast<char*>(&num) == 1;
}
///////////////////
// binary reader //
///////////////////
@@ -117,18 +131,6 @@ class binary_reader
return result;
}
/*!
@brief determine system byte order
@return true if and only if system's byte order is little endian
@note from https://stackoverflow.com/a/1001328/266378
*/
static constexpr bool little_endianess(int num = 1) noexcept
{
return *reinterpret_cast<char*>(&num) == 1;
}
private:
//////////
// BSON //