std::array was designed to be a zero-overhead wrapper for C-style array while providing the value like semantics of other C++ containers. Why would std::fixed_string be any different by being excessively bloaty and resource wasteful?
std::array is basically defined as:
1 2 3 4 5 6 7 8
|
template<typename T, size_t N>
struct array
{
T _data[N];
T& operator[](size_t);
const T& operator[](size_t) const;
// other member functions and typedefs
};
| |
std::fixed_string could be a template specialization of std::array for working with strings/characters and a class name change. The details of dealing with a string array are different than a regular array, though.
Passing a C array, string or otherwise, into a non-template function effectively devolves the array to a pointer so the function doesn't know what the size of the array unless passed as a separate parameter. std::fixed_string would "remember" its size, just as std::array does.
Yes, std::array is an aggregate, so std::fixed_string likely would be as well.
A C-style array and its elements are allocated on the stack unless new is used. A std::array's elements are stack-based as well, and can't have the elements on the free store/heap.
Hiding all the messy details of dealing with read-only C-style arrays in a C++ wrapper would be IMO advantageous since the proposal appears to have a similar interface to std::string.
If you need the ability to change the contents using a std::string would be the thing to do.