331 Commits

Author SHA1 Message Date
Gennaro Prota 2ff9d3535e Don't qualify string_view in the available() test's pos/count append() case
Reason: Using the basic_string_view type used by the library.

This fixes the previous commit.
boost-1.92.0.beta1
2026-04-24 07:05:02 +02:00
Gennaro Prota 8c44a96c8d Use std::string_view in the available() test's pos/count append() example
The test I added with available() passed "xyzwv" directly to the 3-arg
append(v, pos, count). That overload's viewable-T constraint excludes
const CharT*-convertible types (to avoid clashing with append(const
CharT*, size_type)), so the C-string literal doesn't match and there is
no viable 3-arg overload. Wrap the literal in std::string_view.
2026-04-24 06:41:11 +02:00
Gennaro Prota bf20b809ec Add basic_static_string::available()
This returns max_size() - size(), i.e. the number of characters that can
still be inserted before the string reaches its capacity. Intended as a
shorthand for capacity-capped writes in combination with the
pos/count-taking overloads of append, assign, and insert:

  str.append(sv, 0, str.available());

Addresses the ergonomic complaint in issue #81 without expanding the
overload set.

Closes issue #81.
2026-04-22 10:06:00 +02:00
Gennaro Prota 9271183ea8 Fix the basic_static_cstring array ctor to respect the no-embedded-NULs invariant
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.
2026-04-21 16:14:06 +02:00
Gennaro Prota 1c3143c18b Fix a static_assert message
The message assumed the argument to the constructor was a string
literal, but that's not required.
2026-04-21 16:14:06 +02:00
Gennaro Prota 62ed5ee17a Fix basic_static_cstring::compare(const CharT*) for over-long inputs
compare(const CharT* s) constructed a temporary basic_static_cstring<N>
from s and delegated to the class-type overload. The constructor throws
std::length_error when traits::length(s) > N, and because compare() is
noexcept, the throw led to std::terminate():

  static_cstring<3> s("abc");
  s.compare("abcd");              // terminate() via noexcept throw

The free operator==() / operator!=() overloads for const CharT*, which
delegate to compare(), had the same flaw.
2026-04-21 16:13:29 +02:00
Gennaro Prota c6cd8074ab Fix the comparison operators for basic_static_cstring
The defaulted operators had the wrong semantics, as they compared the
entire data_ buffer. The bug showed up when shrinking:

  static_cstring<10> s("hello");
  s.assign("hi", 2);              // data_[3..4] still "lo"
  static_cstring<10> fresh("hi");
  assert(s == fresh);             // FAILED
2026-04-21 11:59:41 +02:00
Gennaro Prota 54eda39d91 Fix a typo in a comment ("compiles" for "compilers") 2026-04-21 11:33:22 +02:00
Gennaro Prota e9313dc331 Add an experimental basic_static_cstring template in example/
This introduces an alternative to basic_static_string designed for use
in POD types: Trivially copyable, having a sizeof == N + 1, with no
embedded NULs.

Placed in example/ to gather user feedback before committing to a public
API. See issue #23.
2025-12-19 19:32:30 +01:00
Gennaro Prota 0c5e5b8e58 Fix our deduction guide 2025-12-19 18:26:40 +01:00
Gennaro Prota 6f0c00b268 Work around a Clang 3.7 bug affecting constexpr insert()
The iterator-based insert(const_iterator, size_type, value_type)
function relies on traits_type::move() to shift the existing null
terminator to its new position. Clang 3.7's constexpr evaluator does not
handle this correctly, causing the following test to fail:

  static_string<3>{"ab"}.insert(2, 1, 'c') == "abc"

Add an explicit term() call, guarded by a preprocessor conditional for
Clang 3.7, to ensure proper null termination.
2025-12-19 18:23:33 +01:00
Gennaro Prota 2175496c55 Condition the NTTP tests on __cpp_nontype_template_args
They were conditioned on detection of C++20 via __cplusplus, but Clang
10 and 11 don't support class types as NTTP, even though they report
C++20 via __cplusplus when -std=c++20 is used.
2025-12-19 18:23:33 +01:00
Gennaro Prota aee3c62957 Apply the workaround in the previous commit to Clang 3.7 and 9-19, too
Reason: They have the same issue as GCC 9.
2025-12-19 18:23:33 +01:00
Gennaro Prota 0e28b358dc Work around GCC 9 rejecting a legitimate pointer comparison in a constexpr context 2025-12-19 18:23:33 +01:00
Gennaro Prota 4dcfb39494 Replace the implementation of cxper_char_traits::move() with a simpler one
Reason: See the new code comment.
2025-12-19 18:23:33 +01:00
Gennaro Prota 4bf6461ca1 Work around a bug in GCC 5-10
GCC 5-10 incorrectly complain about our nested classes being private.
So, make them public.
2025-12-19 18:23:33 +01:00
Krystian Stasiowski 67efdf6a9b Make basic_static_string usable as a NTTP 2025-12-19 18:23:33 +01:00
Krystian Stasiowski 3a410b8472 Add build directory and CMake preset files to .gitignore 2025-12-19 18:23:33 +01:00
Gennaro Prota bf988466f8 Work around GCC (libstdc++) bug #113200
See the previous commit. This simple fix avoids calling Traits::move(),
which is where the bug resides.

This closes issue #55.
2025-12-16 10:30:33 +01:00
Gennaro Prota a526ebd1f6 Check that basic_static_string can be constructed and assigned from a C-style string in a constexpr context
This triggers a libstdc++ issue which was fixed in GCC 12.4 and 13.3:
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113200>. If our CI shows
we bump into that bug, we'll add a workaround.
2025-12-16 10:30:33 +01:00
Gennaro Prota 2f8c7a69ea Update the library metadata: Remove Krystian, add myself as a maintainer 2025-12-15 14:25:26 +01:00
Gennaro Prota c915934529 Fix four occorrences of a typo ("arugment") in the Javadoc comments boost-1.91.0.beta1 boost-1.91.0 boost-1.90.0 2025-11-14 12:03:00 +01:00
Gennaro Prota 10b5491104 Avoid two C4244 warnings from MSVC 2025-11-05 11:30:41 +01:00
Alexander Grund a58319dbdd Switch boost.io to boost.org boost-1.90.0.beta1 2025-10-24 11:59:10 +02:00
Alexander Grund 4c84b61975 README: Replace travis badges by GHA badges 2025-10-24 11:59:10 +02:00
Alexander Grund fbd6051165 Update Link to regression test matrix in README 2025-10-24 11:59:10 +02:00
Alexander Grund db1ea76a17 Fix required CMake version
`source_group(TREE` requires CMake 3.8
2025-10-24 11:58:47 +02:00
Alexander Grund ee172b86fd Try standalone only with >=C++17 2025-10-24 11:57:55 +02:00
Alexander Grund bd3dd01259 Update Drone from Boost.CI 2025-10-24 11:57:55 +02:00
Gennaro Prota a841869405 Remove a use of std::strcpy() to avoid a C4996 warning from MSVC 2025-10-24 11:00:21 +02:00
Alexander Grund 3613e9578d Fix standalone build with Clang
The config.hpp uses `BOOST_LIBSTDCXX_VERSION` which isn't defined in
standalone mode so `BOOST_STATIC_STRING_NO_CXX17_HDR_STRING_VIEW` will
be defined.
This then causes build failures for code expecting the availability of
string_view.
2025-10-24 10:11:37 +02:00
Alexander Grund 6f17b60377 Guard test requiring string_view 2025-10-24 10:11:37 +02:00
Gennaro Prota 815678e1e7 CI: Test C++26/2c again 2025-10-23 16:49:48 +02:00
Gennaro Prota 2cc22bf5a8 Align to_static_[w]string() with C++26 std::to_[w]string()
C++26 specifies that std::to_string() and std::to_wstring() format
floating point values as if using std::format(). This commit updates the
internal conversion helpers to match that behavior, using
std::format_to_n() for efficient, allocation-free formatting directly
into the static_string/static_wstring buffer.

Fallbacks using snprintf()/swprintf() remain active for pre-C++26
builds.

This ensures consistent formatting across standard and Boost APIs.
2025-10-23 16:49:48 +02:00
Gennaro Prota d6f976a7df Fix the sizes of the strings returned by to_static_string() and to_static_wstring() for floating point values 2025-10-23 16:49:48 +02:00
Gennaro Prota 7b564d8d26 Fix two macro names in the unit tests 2025-10-22 19:18:39 +02:00
Gennaro Prota 3c37deed99 Fix the previous commit 2025-10-22 19:11:09 +02:00
Gennaro Prota 34ef5c45be Remove an unused dependency on Boost.StaticAssert
This closes issue #73.
2025-10-22 19:06:12 +02:00
Kenneth Reitz 0f34644488 Update libraries.json /s/container/containers
The other libraries reference "containers" instead of "container"
2025-10-22 18:48:18 +02:00
Dmitry Arkhipov 4c27826548 use Python version of Docca 2025-10-22 18:35:38 +02:00
Gennaro Prota 9c5d69475d Implement the arithmetic conversions in terms of resize_and_overwrite()
Reason: Performing the conversions without accessing private members,
providing a model for users to implement their own with comparable
efficiency.
2025-10-09 17:45:16 +02:00
Gennaro Prota 300781d954 Add a resize_and_overwrite() member
Reason: This is in preparation of the next commit. See its commit
message.
2025-10-09 17:45:16 +02:00
Gennaro Prota cd1a1a41c3 Don't use an additional buffer in the arithmetic conversions
In the case of the floating point conversions, this effectively avoids a
copy of the buffer contents. In the case of the integer conversions, it
doesn't eliminate the copy, but still removes the extra buffer.

This fixes issue #65.
2025-10-09 17:45:16 +02:00
Alexander Grund 0d255f7438 Appveyor: Update MinGW 32bit job
Use the variant from Boost.CI

Fixes #68
2025-10-07 10:19:31 +02:00
Alexander Grund 17d77ef5bb Disable multi-arch CI job 2025-10-06 17:22:47 +02:00
Alexander Grund 20afd07676 Pass char arrays instead of static_string instances to testR
Avoid stack overflow in MSVC caused by huge amount of static_string instances

Fixes #70
2025-10-06 17:22:47 +02:00
Alexander Grund 7f903ef7ce Add cxx11_hdr_type_traits B2 requirement
Avoid failures with GCC < 5
2025-10-06 17:22:47 +02:00
Alexander Grund 5dfbb1f2b1 CI: Disable coverage and coverity jobs 2025-10-06 17:22:47 +02:00
Arthur O'Dwyer 37a557d937 Make static_string trivially copyable 2025-10-03 18:42:10 +02:00
Alexander Grund cd546285c4 CI: Don't test C++26/2c 2025-10-03 12:12:05 +02:00