A small fixed-capacity string type for embedded C++ projects.
mne::embedded::fixed_string<N> stores characters in a statically sized std::array<char, N> and avoids dynamic allocation in the string object itself. It is intended for microcontroller code where bounded memory usage, predictable behavior and simple interfaces matter.
This repository is an initial extraction of fixed_string.hpp from a private embedded C++ framework.
The header is usable as a starting point, but the repository is still young:
- unit tests are not included yet,
- CI is not configured yet,
- the public API may still change.
- fixed maximum capacity at compile time,
- null-terminated internal character buffer,
- assignment from
std::string_view, - conversion to
std::string_view, c_str(),data(),size(),empty(),capacity()andclear(),- simple error code for assignment overflow/out-of-range cases.
include/
mne/
embedded/
fixed_string.hpp
README.md
LICENSE
#include "mne/embedded/fixed_string.hpp"
#include <string_view>
void consume(std::string_view text);
int main()
{
mne::embedded::fixed_string<32> message {};
const auto result = message.assign("Hello embedded C++");
if (result == mne::embedded::FixedStringError::none)
{
consume(message);
}
}The type is meant for code where the maximum string size is known at compile time. It can be useful for small status texts, protocol fields, labels, diagnostics or configuration values with fixed upper bounds.
For strict embedded projects, review the header against your project rules before production use. In particular, check allowed standard library headers, stream usage, exception policy and naming conventions.
- Add unit tests.
- Add examples.
- Review includes and remove unused dependencies.
- Add CI for common compilers.