
Peter Dimov
Louis Dionne wrote:
`constexpr` char arrays and character packs are not equivalent. The problem is that constexpr-ness is stripped away by argument passing. For illustration, consider the following example:
template <typename CompileTimeString> void f(CompileTimeString s) { static_assert(s == "abc", ""); }
constexpr std::string_literal<n> n4121 = "abc"; constexpr auto n4236 = "abc"_s;
f(n4121); // error: s is not constexpr within the body of f f(n4236); // ok: the value of s is contained in its type
I assume that you mean for 'f' to be constexpr?
No, it does not change a thing. It was on purpose that I did _not_ make it constexpr, in order not to mix concerns. What we're interested in is the constexpr-ness of `s` within the body of `f`, whether `f` is constexpr or not does not change anything. The above scenario is equivalent to something I presented in my C++Now talk [1]. The same concept is also explained in Hana's tutorial, in the "Advanced constexpr" section [2]. It seems that anyone trying to design something constexpr for the standard should have a solid grasp of those concepts, or we may very well end up missing the target of offering a useful compile-time string facility in C++17. Regards, Louis [1]: http://ldionne.com/hana-cppnow-2015/#/19/2 [2]: http://ldionne.com/hana/#tutorial-appendix-constexpr