Here's a way of achieving this
// GOAL
std::array<char, sizeof("Hello")> myarray = {"Hello"};
ie. initializing std::array with a string literal (yes, it used a macro)
// SOLUTION
#define STD_CHAR_ARRAY_INIT(arrayname, string_literal) /*std::array*/<char, sizeof(string_literal)> arrayname = {string_literal}
std::array STD_CHAR_ARRAY_INIT(myarray, "Hello");
Here's some test code:
#include <iostream>
#include <array>
using std::cout;
using std::ostream;
template<typename T, size_t N>
std::ostream& std::operator<<(std::ostream& os, array<T, N> arr)
{
{
size_t cnt = 0;
char strchar[2] = "x";
for (const T& c : arr) {
strchar[0] = c;
os << "arr[" << cnt << "] = '" << (c == '\0' ? "\\0" : strchar /*string(1, c)*/ ) << "'\n"
<< '.' << c << '.' << '\n';
++cnt;
}
}
return os;
}
#define STD_CHAR_ARRAY_INIT(arrayname, string_literal) /*std::array*/<char, sizeof(string_literal)> arrayname = {string_literal}
int main()
{
std::array STD_CHAR_ARRAY_INIT(myarray, "Hello");
cout << myarray << '\n';
return 0;
}