C++ Logo

std-proposals

Advanced search

[std-proposals] Utilizing constant folding with provable if statements

From: Jan Schultke <janschultke_at_[hidden]>
Date: Thu, 24 Aug 2023 02:19:34 +0200
https://gist.github.com/Eisenwave/1520b4bc51b402936fa7c9c653ea29f3

I'm working on a proposal draft for "provable if statements".
In essence, the conditions of an `if provable (expr)` are not
evaluated at run-time.
However, if the compiler can prove that `expr` is `true` despite not
evaluating `expr`,
then the statement is equivalent to `if (true)` without evaluation taking place.

This might seem complex and difficult to implement at first glance,
but it is basically just standardizing existing practice in the form
of `__builtin_constant_p`.

I am really excited for the numerous possibilities this opens up.
Please let me know if there are any open questions,
how the wording can be improved, etc.

This probably still needs a lot of work before it's ready for EWG.

Received on 2023-08-24 00:19:46