4 ms·
If the `const char*` is a compile-time value, you can get its size via `std::char_traits<char>::length()`. Here I could get `magic_functor<std::source_location
by ynik 3y ago
If the `const char*` is a compile-time value, you can get its size via `std::char_traits<char>::length()`.
Here I could get `magic_functor<std::source_location::file_name()>::type` to work on MSVC: https://godbolt.org/z/Ph8dd78fa https://godbolt.org/z/Ph8dd78fa
gcc doesn't accept this code, but that seems more like an implementation problem than a specification problem?
- gpderetta 3y agoThere are a lot of restrictions on what a pointer-type template parameter can point to. In particular it needs to have linkage (which for example string literals do not have). Whether the results of constexpr functions must, can or can't have linkage is beyond my paygrade, but I suspect this is an MSVC extension. edit: linkage appears to propagate through constexpr. So it depends on how ultimately the original string is generated. I don't know what guarantee the standard gives (cppreference doesn't mention anything and I can't be bothered to look at the standard).