Skip to content

Commit

Permalink
Add to_char_type function to custom char_traits
Browse files Browse the repository at this point in the history
  • Loading branch information
colbychaskell committed Nov 25, 2023
1 parent bd9cb20 commit 299e426
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
18 changes: 14 additions & 4 deletions include/nlohmann/detail/meta/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,17 @@ struct char_traits<unsigned char> : std::char_traits<char>
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<int_type>(c);
}

static constexpr int_type eof()
static char_type to_char_type(int_type i) noexcept
{
return static_cast<char_type>(i);
}

static constexpr int_type eof() noexcept
{
return static_cast<int_type>(EOF);
}
Expand All @@ -218,12 +223,17 @@ struct char_traits<signed char> : std::char_traits<char>
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<int_type>(c);
}

static constexpr int_type eof()
static char_type to_char_type(int_type i) noexcept
{
return static_cast<char_type>(i);
}

static constexpr int_type eof() noexcept
{
return static_cast<int_type>(EOF);
}
Expand Down
18 changes: 14 additions & 4 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3606,12 +3606,17 @@ struct char_traits<unsigned char> : std::char_traits<char>
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<int_type>(c);
}

static constexpr int_type eof()
static char_type to_char_type(int_type i) noexcept
{
return static_cast<char_type>(i);
}

static constexpr int_type eof() noexcept
{
return static_cast<int_type>(EOF);
}
Expand All @@ -3625,12 +3630,17 @@ struct char_traits<signed char> : std::char_traits<char>
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<int_type>(c);
}

static constexpr int_type eof()
static char_type to_char_type(int_type i) noexcept
{
return static_cast<char_type>(i);
}

static constexpr int_type eof() noexcept
{
return static_cast<int_type>(EOF);
}
Expand Down

0 comments on commit 299e426

Please sign in to comment.