I want to do the following:
std::unique_ptr buffer = new char[ /* ... */ ] { \"/tmp/file-XXXXXX\" };
Obviously, it doesn\'t work
Here's a solution based on std::array:
std::array arr{ "/tmp/file-XXXXXX" };
You can reduce the boilerplate using a macro:
#define DECLARE_LITERAL_ARRAY(name, str) std::array name{ str }
DECLARE_LITERAL_ARRAY(arr, "/tmp/file-XXXXXX");
The sizeof is evaluated at compile-time, so there is no runtime scanning of the literal string to find its length. The resulting array is null-terminated, which you probably want anyway.