From 543158bbf3efe123d59832e26a89ebf63c9e5eb7 Mon Sep 17 00:00:00 2001 From: Colby Haskell Date: Mon, 13 Nov 2023 13:27:14 -0500 Subject: [PATCH] Add to_char_type function to custom char_traits --- include/nlohmann/detail/meta/type_traits.hpp | 18 ++++++++++++++---- single_include/nlohmann/json.hpp | 18 ++++++++++++++---- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/include/nlohmann/detail/meta/type_traits.hpp b/include/nlohmann/detail/meta/type_traits.hpp index b1e7022ab1..82faf0de8c 100644 --- a/include/nlohmann/detail/meta/type_traits.hpp +++ b/include/nlohmann/detail/meta/type_traits.hpp @@ -199,12 +199,17 @@ struct char_traits : std::char_traits using int_type = uint64_t; // Redefine to_int_type function - static int_type to_int_type(char_type c) + static int_type to_int_type(char_type c) noexcept { return static_cast(c); } - static constexpr int_type eof() + static char_type to_char_type(int_type i) noexcept + { + return static_cast(i); + } + + static constexpr int_type eof() noexcept { return static_cast(EOF); } @@ -218,12 +223,17 @@ struct char_traits : std::char_traits using int_type = uint64_t; // Redefine to_int_type function - static int_type to_int_type(char_type c) + static int_type to_int_type(char_type c) noexcept { return static_cast(c); } - static constexpr int_type eof() + static char_type to_char_type(int_type i) noexcept + { + return static_cast(i); + } + + static constexpr int_type eof() noexcept { return static_cast(EOF); } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index a930988ff4..09db5f1dc1 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -3612,12 +3612,17 @@ struct char_traits : std::char_traits using int_type = uint64_t; // Redefine to_int_type function - static int_type to_int_type(char_type c) + static int_type to_int_type(char_type c) noexcept { return static_cast(c); } - static constexpr int_type eof() + static char_type to_char_type(int_type i) noexcept + { + return static_cast(i); + } + + static constexpr int_type eof() noexcept { return static_cast(EOF); } @@ -3631,12 +3636,17 @@ struct char_traits : std::char_traits using int_type = uint64_t; // Redefine to_int_type function - static int_type to_int_type(char_type c) + static int_type to_int_type(char_type c) noexcept { return static_cast(c); } - static constexpr int_type eof() + static char_type to_char_type(int_type i) noexcept + { + return static_cast(i); + } + + static constexpr int_type eof() noexcept { return static_cast(EOF); }