EVMC
evmc::byte_traits< T > Struct Template Reference

The char traits for byte-like types. More...

#include <bytes.hpp>

Inheritance diagram for evmc::byte_traits< T >:

Public Types

using char_type = T
 The byte type.
 

Static Public Member Functions

static constexpr void assign (char_type &c1, const char_type &c2)
 Assigns c2 to c1.
 
static constexpr char_typeassign (char_type *ptr, std::size_t count, char_type value)
 Assigns value to each byte in [ptr, ptr+count).
 
static constexpr bool eq (char_type a, char_type b)
 Returns true if bytes are equal.
 
static constexpr bool lt (char_type a, char_type b)
 Returns true if byte a is less than byte b.
 
static constexpr char_typemove (char_type *dest, const char_type *src, std::size_t count)
 Copies count bytes from src to dest. Performs correctly even if ranges overlap.
 
static constexpr char_typecopy (char_type *dest, const char_type *src, std::size_t count)
 Copies count bytes from src to dest. The ranges must not overlap.
 
static constexpr int compare (const char_type *a, const char_type *b, std::size_t count)
 Compares lexicographically the bytes in two ranges of equal length.
 
static std::size_t length (const char_type *s)
 Returns the length of a null-terminated byte string.
 
static constexpr const char_typefind (const char_type *s, std::size_t count, const char_type &value)
 Finds the value in the range of bytes and returns the pointer to the first occurrence or nullptr if not found.
 

Detailed Description

template<typename T>
struct evmc::byte_traits< T >

The char traits for byte-like types.

See: https://en.cppreference.com/w/cpp/string/char_traits.

Definition at line 17 of file bytes.hpp.

Member Typedef Documentation

◆ char_type

template<typename T >
using evmc::byte_traits< T >::char_type = T

The byte type.

Definition at line 21 of file bytes.hpp.

Member Function Documentation

◆ assign() [1/2]

template<typename T >
static constexpr void evmc::byte_traits< T >::assign ( char_type c1,
const char_type c2 
)
inlinestaticconstexpr

Assigns c2 to c1.

Definition at line 24 of file bytes.hpp.

24{ c1 = c2; }

◆ assign() [2/2]

template<typename T >
static constexpr char_type * evmc::byte_traits< T >::assign ( char_type ptr,
std::size_t  count,
char_type  value 
)
inlinestaticconstexpr

Assigns value to each byte in [ptr, ptr+count).

Definition at line 27 of file bytes.hpp.

28 {
29 std::fill_n(ptr, count, value);
30 return ptr;
31 }

◆ compare()

template<typename T >
static constexpr int evmc::byte_traits< T >::compare ( const char_type a,
const char_type b,
std::size_t  count 
)
inlinestaticconstexpr

Compares lexicographically the bytes in two ranges of equal length.

Definition at line 57 of file bytes.hpp.

58 {
59 for (; count != 0; --count, ++a, ++b)
60 {
61 if (lt(*a, *b))
62 return -1;
63 if (lt(*b, *a))
64 return 1;
65 }
66 return 0;
67 }
static constexpr bool lt(char_type a, char_type b)
Returns true if byte a is less than byte b.
Definition: bytes.hpp:37

◆ copy()

template<typename T >
static constexpr char_type * evmc::byte_traits< T >::copy ( char_type dest,
const char_type src,
std::size_t  count 
)
inlinestaticconstexpr

Copies count bytes from src to dest. The ranges must not overlap.

Definition at line 50 of file bytes.hpp.

51 {
52 std::copy_n(src, count, dest);
53 return dest;
54 }

◆ eq()

template<typename T >
static constexpr bool evmc::byte_traits< T >::eq ( char_type  a,
char_type  b 
)
inlinestaticconstexpr

Returns true if bytes are equal.

Definition at line 34 of file bytes.hpp.

34{ return a == b; }

◆ find()

template<typename T >
static constexpr const char_type * evmc::byte_traits< T >::find ( const char_type s,
std::size_t  count,
const char_type value 
)
inlinestaticconstexpr

Finds the value in the range of bytes and returns the pointer to the first occurrence or nullptr if not found.

Definition at line 78 of file bytes.hpp.

81 {
82 const auto end = s + count;
83 const auto p = std::find(s, end, value);
84 return p != end ? p : nullptr;
85 }

◆ length()

template<typename T >
static std::size_t evmc::byte_traits< T >::length ( const char_type s)
inlinestatic

Returns the length of a null-terminated byte string.

Definition at line 71 of file bytes.hpp.

72 {
73 return std::strlen(reinterpret_cast<const char*>(s));
74 }

◆ lt()

template<typename T >
static constexpr bool evmc::byte_traits< T >::lt ( char_type  a,
char_type  b 
)
inlinestaticconstexpr

Returns true if byte a is less than byte b.

Definition at line 37 of file bytes.hpp.

37{ return a < b; }

◆ move()

template<typename T >
static constexpr char_type * evmc::byte_traits< T >::move ( char_type dest,
const char_type src,
std::size_t  count 
)
inlinestaticconstexpr

Copies count bytes from src to dest. Performs correctly even if ranges overlap.

Definition at line 40 of file bytes.hpp.

41 {
42 if (dest < src)
43 std::copy_n(src, count, dest);
44 else if (src < dest)
45 std::copy_backward(src, src + count, dest + count);
46 return dest;
47 }

The documentation for this struct was generated from the following file: