mirror of
https://github.com/nlohmann/json.git
synced 2025-08-07 18:02:57 +03:00
Replace deprecated std::is_trivial in C++26 (#4775)
This commit is contained in:
@@ -32,8 +32,14 @@
|
|||||||
|
|
||||||
// C++ language standard detection
|
// C++ language standard detection
|
||||||
// if the user manually specified the used C++ version, this is skipped
|
// if the user manually specified the used C++ version, this is skipped
|
||||||
#if !defined(JSON_HAS_CPP_23) && !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11)
|
#if !defined(JSON_HAS_CPP_26) && !defined(JSON_HAS_CPP_23) && !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11)
|
||||||
#if (defined(__cplusplus) && __cplusplus > 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG > 202002L)
|
#if (defined(__cplusplus) && __cplusplus > 202302L) || (defined(_MSVC_LANG) && _MSVC_LANG > 202302L)
|
||||||
|
#define JSON_HAS_CPP_26
|
||||||
|
#define JSON_HAS_CPP_23
|
||||||
|
#define JSON_HAS_CPP_20
|
||||||
|
#define JSON_HAS_CPP_17
|
||||||
|
#define JSON_HAS_CPP_14
|
||||||
|
#elif (defined(__cplusplus) && __cplusplus > 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG > 202002L)
|
||||||
#define JSON_HAS_CPP_23
|
#define JSON_HAS_CPP_23
|
||||||
#define JSON_HAS_CPP_20
|
#define JSON_HAS_CPP_20
|
||||||
#define JSON_HAS_CPP_17
|
#define JSON_HAS_CPP_17
|
||||||
|
@@ -35,6 +35,7 @@
|
|||||||
#undef JSON_HAS_CPP_17
|
#undef JSON_HAS_CPP_17
|
||||||
#undef JSON_HAS_CPP_20
|
#undef JSON_HAS_CPP_20
|
||||||
#undef JSON_HAS_CPP_23
|
#undef JSON_HAS_CPP_23
|
||||||
|
#undef JSON_HAS_CPP_26
|
||||||
#undef JSON_HAS_FILESYSTEM
|
#undef JSON_HAS_FILESYSTEM
|
||||||
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
|
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
|
||||||
#undef JSON_HAS_THREE_WAY_COMPARISON
|
#undef JSON_HAS_THREE_WAY_COMPARISON
|
||||||
|
@@ -1813,8 +1813,21 @@ class binary_writer
|
|||||||
enable_if_t < std::is_signed<C>::value && std::is_unsigned<char>::value > * = nullptr >
|
enable_if_t < std::is_signed<C>::value && std::is_unsigned<char>::value > * = nullptr >
|
||||||
static CharType to_char_type(std::uint8_t x) noexcept
|
static CharType to_char_type(std::uint8_t x) noexcept
|
||||||
{
|
{
|
||||||
static_assert(sizeof(std::uint8_t) == sizeof(CharType), "size of CharType must be equal to std::uint8_t");
|
// The std::is_trivial trait is deprecated in C++26. The replacement is to use
|
||||||
|
// std::is_trivially_copyable and std::is_trivially_default_constructible.
|
||||||
|
// However, some older library implementations support std::is_trivial
|
||||||
|
// but not all the std::is_trivially_* traits.
|
||||||
|
// Since detecting full support across all libraries is difficult,
|
||||||
|
// we use std::is_trivial unless we are using a standard where it has been deprecated.
|
||||||
|
// For more details, see: https://github.com/nlohmann/json/pull/4775#issuecomment-2884361627
|
||||||
|
#ifdef JSON_HAS_CPP_26
|
||||||
|
static_assert(std::is_trivially_copyable<CharType>::value, "CharType must be trivially copyable");
|
||||||
|
static_assert(std::is_trivially_default_constructible<CharType>::value, "CharType must be trivially default constructible");
|
||||||
|
#else
|
||||||
static_assert(std::is_trivial<CharType>::value, "CharType must be trivial");
|
static_assert(std::is_trivial<CharType>::value, "CharType must be trivial");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static_assert(sizeof(std::uint8_t) == sizeof(CharType), "size of CharType must be equal to std::uint8_t");
|
||||||
CharType result;
|
CharType result;
|
||||||
std::memcpy(&result, &x, sizeof(x));
|
std::memcpy(&result, &x, sizeof(x));
|
||||||
return result;
|
return result;
|
||||||
|
@@ -2395,8 +2395,14 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
|
|
||||||
// C++ language standard detection
|
// C++ language standard detection
|
||||||
// if the user manually specified the used C++ version, this is skipped
|
// if the user manually specified the used C++ version, this is skipped
|
||||||
#if !defined(JSON_HAS_CPP_23) && !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11)
|
#if !defined(JSON_HAS_CPP_26) && !defined(JSON_HAS_CPP_23) && !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11)
|
||||||
#if (defined(__cplusplus) && __cplusplus > 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG > 202002L)
|
#if (defined(__cplusplus) && __cplusplus > 202302L) || (defined(_MSVC_LANG) && _MSVC_LANG > 202302L)
|
||||||
|
#define JSON_HAS_CPP_26
|
||||||
|
#define JSON_HAS_CPP_23
|
||||||
|
#define JSON_HAS_CPP_20
|
||||||
|
#define JSON_HAS_CPP_17
|
||||||
|
#define JSON_HAS_CPP_14
|
||||||
|
#elif (defined(__cplusplus) && __cplusplus > 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG > 202002L)
|
||||||
#define JSON_HAS_CPP_23
|
#define JSON_HAS_CPP_23
|
||||||
#define JSON_HAS_CPP_20
|
#define JSON_HAS_CPP_20
|
||||||
#define JSON_HAS_CPP_17
|
#define JSON_HAS_CPP_17
|
||||||
@@ -17605,8 +17611,21 @@ class binary_writer
|
|||||||
enable_if_t < std::is_signed<C>::value && std::is_unsigned<char>::value > * = nullptr >
|
enable_if_t < std::is_signed<C>::value && std::is_unsigned<char>::value > * = nullptr >
|
||||||
static CharType to_char_type(std::uint8_t x) noexcept
|
static CharType to_char_type(std::uint8_t x) noexcept
|
||||||
{
|
{
|
||||||
static_assert(sizeof(std::uint8_t) == sizeof(CharType), "size of CharType must be equal to std::uint8_t");
|
// The std::is_trivial trait is deprecated in C++26. The replacement is to use
|
||||||
|
// std::is_trivially_copyable and std::is_trivially_default_constructible.
|
||||||
|
// However, some older library implementations support std::is_trivial
|
||||||
|
// but not all the std::is_trivially_* traits.
|
||||||
|
// Since detecting full support across all libraries is difficult,
|
||||||
|
// we use std::is_trivial unless we are using a standard where it has been deprecated.
|
||||||
|
// For more details, see: https://github.com/nlohmann/json/pull/4775#issuecomment-2884361627
|
||||||
|
#ifdef JSON_HAS_CPP_26
|
||||||
|
static_assert(std::is_trivially_copyable<CharType>::value, "CharType must be trivially copyable");
|
||||||
|
static_assert(std::is_trivially_default_constructible<CharType>::value, "CharType must be trivially default constructible");
|
||||||
|
#else
|
||||||
static_assert(std::is_trivial<CharType>::value, "CharType must be trivial");
|
static_assert(std::is_trivial<CharType>::value, "CharType must be trivial");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static_assert(sizeof(std::uint8_t) == sizeof(CharType), "size of CharType must be equal to std::uint8_t");
|
||||||
CharType result;
|
CharType result;
|
||||||
std::memcpy(&result, &x, sizeof(x));
|
std::memcpy(&result, &x, sizeof(x));
|
||||||
return result;
|
return result;
|
||||||
@@ -25407,6 +25426,7 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC
|
|||||||
#undef JSON_HAS_CPP_17
|
#undef JSON_HAS_CPP_17
|
||||||
#undef JSON_HAS_CPP_20
|
#undef JSON_HAS_CPP_20
|
||||||
#undef JSON_HAS_CPP_23
|
#undef JSON_HAS_CPP_23
|
||||||
|
#undef JSON_HAS_CPP_26
|
||||||
#undef JSON_HAS_FILESYSTEM
|
#undef JSON_HAS_FILESYSTEM
|
||||||
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
|
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
|
||||||
#undef JSON_HAS_THREE_WAY_COMPARISON
|
#undef JSON_HAS_THREE_WAY_COMPARISON
|
||||||
|
Reference in New Issue
Block a user