On Fri, Nov 15, 2019 at 2:58 PM Thiago Macieira via Std-Discussion <std-discussion@lists.isocpp.org> wrote:
On sexta-feira, 15 de novembro de 2019 10:26:41 PST Brian Bi via Std-
Discussion wrote:
> There has been a push to declare as many standard library functions
> constexpr as possible. However, declaring a function constexpr does not
> guarantee that a call to that function will be a constant expression. If we
> don't know whether a call will be a constant expression, then the fact that
> it is marked constexpr is useless.
>
> In most cases, the standard does not specify the way in which standard
> library functions are implemented, as this is considered an implementation
> detail. However, in the case of a constexpr function, these implementation
> details actually become part of the function's interface, because they
> determine whether or not the function will be usable in a constant
> expression.
>
> Obviously the call cannot be a constant expression if the library function
> is specified to invoke some other function that is not constexpr (e.g.,
> std::sort invokes the user's comparator). However, it's not entirely clear
> to me what happens in all other cases.

Your only guarantee is that if you use that function in a constexpr context,
it'll be a constant expression. If you use in another context, then you can't
guarantee anything.

What do you mean by "constexpr context"?
 

Why does it matter?

It matters because it determines whether:

    constexpr auto x = some_constexpr_library_function(some_args)

actually compiles.
 

--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel System Software Products



--
Std-Discussion mailing list
Std-Discussion@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion


--
Brian Bi