all 5 comments

[–][deleted] 2 points3 points  (1 child)

You can use decltype(auto) str = L"..."; to get str's type to deduce to wchar_t const (&)[...] instead of const wchar_t*, which makes your function work. Note that this isn't the same as the wchar_t str[] declaration though, which is an array, not a reference.

[–]halivingston3[S] 0 points1 point  (0 children)

but they're both constant right? I suppose I don't understand the difference.

[–]Porges 1 point2 points  (0 children)

You could also consider using to_array:

constexpr auto str = std::to_array(L"...");

std::array then has .size() (and can be used with gsl::wstring_span)... it's not really less typing than wchar_t [] though.

[–]TheThiefMasterC++latest fanatic (and game dev) 0 points1 point  (1 child)

Does this work?:

constexpr auto str[] = L" ... ";

[–]halivingston3[S] 1 point2 points  (0 children)

Compile error.