Boost logo

Boost :

Subject: Re: [boost] [metaparse] performance comparisons?
From: Louis Dionne (ldionne.2_at_[hidden])
Date: 2015-06-02 08:54:15


Peter Dimov <lists <at> pdimov.com> writes:

>
> 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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk