char_traits#

Fully qualified name: carb::cpp::char_traits

Defined in carb/cpp/detail/CharTraits.h

template<typename CharT>
struct char_traits : public std::char_traits<CharT>#

This struct provides implementations of a subset of the functions found in std::char_traits.

It is used to provide constexpr implementations of the functions because std::char_traits did not become constexpr until C++20. Currently only the methods used by omni::string and omni::string_view are provided.

Public Types

using char_type = typename std::char_traits<CharT>::char_type#

Base type for a character value.

using int_type = typename std::char_traits<CharT>::int_type#

Base type for an integer value.

using off_type = typename std::char_traits<CharT>::off_type#

Base type for an offset value.

using pos_type = typename std::char_traits<CharT>::pos_type#

Base type for a position in a string.

using state_type = typename std::char_traits<CharT>::state_type#

Base type for a state value.

using comparison_category = typename std::char_traits<CharT>::comparison_category#

Base type for a character comparison result.

Public Static Functions

static inline constexpr char_type *assign(
char_type *dest,
std::size_t count,
const char_type c,
) noexcept#

Assigns count copies of c to dest.

Returns:

dest.

static inline constexpr char_type *move(
char_type *dest,
const char_type *source,
std::size_t count,
) noexcept#

Copies count characters from source to dest.

This function performs correctly even if dest and source overlap.

Returns:

dest

static inline constexpr char_type *copy(
char_type *const dest,
const char_type *const source,
std::size_t const count,
) noexcept#

Copies count characters from source to dest.

Behavior of this function is undefined if dest and source overlap.

Returns:

dest

static inline constexpr void assign(
char_type &dest,
const char_type &c,
) noexcept#

Assigns c to dest.

static inline constexpr int compare(
const char_type *s1,
const char_type *s2,
std::size_t count,
) noexcept#

Lexicographically compares the first count characters of s1 and s2.

Returns:

Negative value if s1 is less than s2. ​0​ if s1 is equal to s2. Positive value if s1 is greater than s2.

static inline constexpr const char_type *find(
const char_type *s,
std::size_t count,
char_type const ch,
) noexcept#

Searches the first count characters of s for the character ch.

Returns:

A pointer to the first character equal to ch, or nullptr if no such character exists.

template<size_t N>
static inline constexpr std::size_t length(
const char_type (&s)[N],
) noexcept#

Computes the length of a bounded array of char_type.

Note

This function is a Carbonite extension. std::char_traits::length behaves differently in that the array must contain a char_type(0) character.

Template Parameters:

N – The array length of s.

Parameters:

s – A bounded array of char_type.

Returns:

The length of s which may equal but not exceed N.

static constexpr std::size_t length(const char_type *s) noexcept#

Computes the length of s.

Note

This function is specialized to be more secure when used with literal strings and character arrays, in which case the maximum length returned will be the number of characters of the literal string or array.

Returns:

The length of s.

static inline constexpr std::size_t length_s(
const char_type *const s,
std::size_t const max_count,
) noexcept#

Computes the length of s bounded by count.

Note

This is a Carbonite extension added for additional security.

Returns:

The length of s or count whichever is smaller.

template<std::size_t N>
static inline constexpr std::size_t length_s(
const char_type (&s)[N],
) noexcept#

Computes the length of s bounded by N.

Note

This is a Carbonite extension added for additional security.

Returns:

The length of s or N whichever is smaller.