mirror of
https://github.com/boostorg/static_string.git
synced 2026-07-21 13:33:30 +00:00
9271183ea8
The constructor taking a const CharT (&)[M] copied M - 1 characters
verbatim via assign(arr, M - 1), preserving any embedded NULs in the
input. This would violate the type's documented "no embedded NULs"
invariant.
const char arr[] = { '1', '2', '\0', '4', '5', '\0' };
static_cstring<5> s(arr);
// data_ holds {'1','2','\0','4','5','\0'} --- embedded NUL stored
Delegate to assign(arr) instead, which uses traits::length() to
determine the size. This matches the behavior of the other
CharT-accepting entry points (assign(const CharT*), the const CharT*
constructor) and makes the invariant self-enforcing at construction.
Note: In practice, this is a bug that would never surface, because the
array constructor is never chosen for static_cstring<N> s(arr)---the
pointer constructor always wins---but the array constructor is needed
for CTAD (deduction guide), so it better be correct.
This also means the test we added is, at the moment, superfluous.
This directory contains an experimental implementation of basic_static_cstring, which differs from basic_static_string in the following ways:
basic_static_cstring |
basic_static_string |
|
|---|---|---|
| Layout | sizeof == N + 1 |
Has size member |
| Embedded NULs | Not supported | Supported |
| Trivially copyable | Yes | No |
Additionally, when N <= UCHAR_MAX, basic_static_cstring employs an optimization that avoids calling std::strlen() to compute the size.
This work stems from boostorg/static_string#23.
If you believe basic_static_cstring should become part of the public API, please share your feedback on the Boost mailing list.