I am looking for a string implementation with fixed upper size that can be used in memcopy environment and that is trivially constructible and copyable.
I found boost beast static_string, but IDK if my example works by accident or no?
#include <algorithm>
#include <iostream>
#include <boost/beast/core/static_string.hpp>
boost::beast::static_string<16> s1("abc");
int main(){
boost::beast::static_string<16> s2;
std::copy_n((char*)&s1, sizeof(s2), (char*)&s2);
s1.push_back('X');
std::cout << "--" << std::endl;
std::cout << s2 << std::endl;
s2.push_back('Y');
std::cout << s2 << std::endl;
std::cout << std::is_trivial_v<decltype(s2)> << std::endl;
}
note: last line says type is not trivially copyable, but it could be just that Vinnie forgott to add a type trait.
P.S. I know this is a generally bad idea, what I am replacing is even worse, just a plain C array and modifying the allocation/copying to support std::string is much much more work.