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 27, 2023
1 parent 6c83919 commit 543158b
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 @@ -3612,12 +3612,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 @@ -3631,12 +3636,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 543158b

Please sign in to comment.