25 const auto len = std::min(src.size(), N - 1);
29 std::memcpy(dst, src.data(), len);
31 std::memset(dst + len, 0, N - len);
32 return len < src.size();
49 static_assert(N > 1,
"fixed_string needs room for at least one character and a terminator");
56 fixed_string(
const char *value)
noexcept {
assign(value ? std::string_view(value) : std::string_view()); }
60 assign(value ? std::string_view(value) : std::string_view());
69 void clear() noexcept { std::memset(data_, 0, N); }
71 const char *
c_str() const noexcept {
return data_; }
72 const char *
data() const noexcept {
return data_; }
73 char *
data() noexcept {
return data_; }
75 size_t size() const noexcept { return ::strnlen(data_, N); }
76 bool empty() const noexcept {
return data_[0] ==
'\0'; }
77 static constexpr size_t capacity() noexcept {
return N - 1; }
80 std::string_view
view() const noexcept {
return std::string_view(data_,
size()); }
81 operator std::string_view() const noexcept {
return view(); }
82 std::string
str()
const {
return std::string(
view()); }
85 return lhs.view() == rhs;
88 return std::memcmp(lhs.data_, rhs.data_, N) == 0;
92 return os << value.
view();
105 return std::hash<std::string_view>{}(value);
111 bool operator()(std::string_view lhs, std::string_view rhs)
const noexcept {
120template<
size_t N,
class CharT>
121struct std::formatter<
slick::sim::utils::fixed_string<N>, CharT> : std::formatter<std::string_view, CharT> {
122 template<
class FormatContext>
124 return std::formatter<std::string_view, CharT>::format(value.
view(), ctx);
A null-terminated character buffer of fixed capacity, stored inline.
const char * data() const noexcept
fixed_string & operator=(std::string_view value) noexcept
fixed_string(std::string_view value) noexcept
static constexpr size_t capacity() noexcept
fixed_string(const char *value) noexcept
friend bool operator==(const fixed_string &lhs, const fixed_string &rhs) noexcept
static constexpr size_t buffer_size() noexcept
friend bool operator==(const fixed_string &lhs, std::string_view rhs) noexcept
void assign(std::string_view value) noexcept
Truncates anything that does not fit and zero-fills the tail, so the buffer is always null-terminated...
size_t size() const noexcept
friend std::ostream & operator<<(std::ostream &os, const fixed_string &value)
fixed_string & operator=(const char *value) noexcept
const char * c_str() const noexcept
std::string_view view() const noexcept
bool empty() const noexcept
Conversions between wire decimals with a constant exponent of -9 (CME PRICE9, ICE Decimal9) and the s...
bool copy_wire_field(char(&dst)[N], std::string_view src) noexcept
Copies a name into a fixed-width wire field.
bool operator()(std::string_view lhs, std::string_view rhs) const noexcept
Transparent hash/equality for maps keyed by fixed_string.
size_t operator()(std::string_view value) const noexcept