An alternative to std::string with inplace storage. STL compliant, can be used as a full replacement of C++17's std::string.
{
using Name = inplace_string<15>; // 16 bytes on stack, size included
Name name = "foo";
auto it = name.find("r");
assert(it == Name::npos);
name += "bar";
std::string str(name); // implicit std::string_view construction
....
}
{
inplace_string<5> too_small;
too_small = "foobar"; // error: static_assert failed "basic_inplace_string: size exceeds maximum capacity"
}
inplace_string<N, CharT, Traits> implements C++17's std::string interface, plus:
max_size()
andcapacity()
areconstexpr
inplace_string
can be constructed fromconst CharT(&)[M])
, allowing a compile-time error if the input exceeds the maximum capacity
Supports Clang >= 3.4, GCC >= 5, VS >= 2017