You need a template literal operator. Functional parameters are never valid constant expressions; even if normal use makes sense, your statement still needs to support an explicit form call
operator "" _a1 ( "hello", 5 );
For integer and floating user literals, there is a boilerplate form that can return an array :
template< char ... c > constexpr std::array< char, sizeof ... (c) > operator "" _a1 () { return { c ... }; }
This is not supported (yet?) For string literals, possibly due to problems with multibyte encoding.
So, you are out of luck in this particular approach.
However, you can take another label and take the string as an array.
template< std::size_t size > constexpr std::array< char, size > string_to_array( char const (&str)[ size ] ) { return string_to_array( str, make_index_helper< size >() ); } template< std::size_t size, std::size_t ... index > constexpr std::array< char, size > string_to_array( char const (&str)[ size ], index_helper< index ... > ) { return {{ str[ index ] ... }}; }
An index_helper support template is required to create an integer count package { 0, 1, 2, ... size } .
Also note that constexpr may not work for the application you have in mind. The constexpr function cannot contain a sequence of peremptory statements. The only statement that allows us to calculate something is the return constructor, or for constexpr , member initialization.
Update: Here is a small demonstration of what you can do in C ++ 11.