Skip to content

Commit cc5d600

Browse files
committed
Add to_char_type function to custom char_traits
1 parent bd9cb20 commit cc5d600

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

include/nlohmann/detail/meta/type_traits.hpp

+14-4
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,17 @@ struct char_traits<unsigned char> : std::char_traits<char>
199199
using int_type = uint64_t;
200200

201201
// Redefine to_int_type function
202-
static int_type to_int_type(char_type c)
202+
static int_type to_int_type(char_type c) noexcept
203203
{
204204
return static_cast<int_type>(c);
205205
}
206206

207-
static constexpr int_type eof()
207+
static char_type to_char_type(int_type i) noexcept
208+
{
209+
return static_cast<char_type>(i);
210+
}
211+
212+
static constexpr int_type eof() noexcept
208213
{
209214
return static_cast<int_type>(EOF);
210215
}
@@ -218,12 +223,17 @@ struct char_traits<signed char> : std::char_traits<char>
218223
using int_type = uint64_t;
219224

220225
// Redefine to_int_type function
221-
static int_type to_int_type(char_type c)
226+
static int_type to_int_type(char_type c) noexcept
222227
{
223228
return static_cast<int_type>(c);
224229
}
225230

226-
static constexpr int_type eof()
231+
static char_type to_char_type(int_type i) noexcept
232+
{
233+
return static_cast<char_type>(i);
234+
}
235+
236+
static constexpr int_type eof() noexcept
227237
{
228238
return static_cast<int_type>(EOF);
229239
}

single_include/nlohmann/json.hpp

+14-4
Original file line numberDiff line numberDiff line change
@@ -3606,12 +3606,17 @@ struct char_traits<unsigned char> : std::char_traits<char>
36063606
using int_type = uint64_t;
36073607

36083608
// Redefine to_int_type function
3609-
static int_type to_int_type(char_type c)
3609+
static int_type to_int_type(char_type c) noexcept
36103610
{
36113611
return static_cast<int_type>(c);
36123612
}
36133613

3614-
static constexpr int_type eof()
3614+
static char_type to_char_type(int_type i) noexcept
3615+
{
3616+
return static_cast<char_type>(i);
3617+
}
3618+
3619+
static constexpr int_type eof() noexcept
36153620
{
36163621
return static_cast<int_type>(EOF);
36173622
}
@@ -3625,12 +3630,17 @@ struct char_traits<signed char> : std::char_traits<char>
36253630
using int_type = uint64_t;
36263631

36273632
// Redefine to_int_type function
3628-
static int_type to_int_type(char_type c)
3633+
static int_type to_int_type(char_type c) noexcept
36293634
{
36303635
return static_cast<int_type>(c);
36313636
}
36323637

3633-
static constexpr int_type eof()
3638+
static char_type to_char_type(int_type i) noexcept
3639+
{
3640+
return static_cast<char_type>(i);
3641+
}
3642+
3643+
static constexpr int_type eof() noexcept
36343644
{
36353645
return static_cast<int_type>(EOF);
36363646
}

0 commit comments

Comments
 (0)