C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Redundify the preprocessor --- Part 1 ---- std::labelled

From: Jan Schultke <janschultke_at_[hidden]>
Date: Wed, 1 Jul 2026 08:31:03 +0200
I agree that there should be a more general solution.

Perhaps Expression Templates could have access to the source representation
of the original expression during expansion, and "procedural macros" with
Token Injection would obviously be able to access the tokens as well.

On Tue, 30 Jun 2026 at 16:53, Sebastian Wittmeier via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> To be honest: I think it is the wrong way. A change in the language for a
> single use case and not even the use case is fully covered.
>
>
>
> The preprocessor is good, because it is flexible.
>
>
>
> Combine your idea with reflection and metaprogramming.
>
> Those are the tools for this stuff.
>
>
> -----Ursprüngliche Nachricht-----
> *Von:* Frederick Virchanza Gotham via Std-Proposals <
> std-proposals_at_[hidden]>
> *Gesendet:* Di 30.06.2026 16:41
> *Betreff:* [std-proposals] Redundify the preprocessor --- Part 1 ----
> std::labelled
> *An:* std-proposals <std-proposals_at_[hidden]>;
> *CC:* Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>;
> If the verb 'redundify' gets added to the English dictionary in the
> coming year, you know it was me who started it.
>
> I think we can work toward making the preprocessor redundant, but
> first we need 'std::labelled'.
>
> So when you have a function signature as follows:
>
> void Func( std::labelled<bool> );
>
> Under the hood it gets compiled to:
>
> void Func( bool, char const * );
>
> And when you invoke it as follows:
>
> Func( current_iterator != container.end() );
>
> The invocation gets compiled under the hood as:
>
> Func( current_iterator != container.end(), "current_iterator !=
> container.end()" );
>
> This would do away with macros such as the following:
>
> #define ASSERT_TRUE(condition)
> \
> do {
> \
> if (!(condition)) {
> \
> std::cerr << "Assertion failed at " << __FILE__ << ":"
> \
> << __LINE__ << "\n"
> \
> << "Expected true, but evaluated to false.\n"
> \
> << "Expression: " << #condition << std::endl;
> \
> std::abort(); /* Or trigger a breakpoint/test failure */
> \
> }
> \
> } while (false)
>
> because they can be re-written as:
>
> inline void AssertTrue(
> std::labelled<bool> condition,
> const std::source_location location =
> std::source_location::current()
> ) {
> if (!condition.value()) {
> std::cerr << "Assertion failed at " <<
> location.file_name() << ":"
> << location.line() << "\n"
> << "Expected true, but evaluated to false.\n"
> << "Expression: " << condition.c_str() << std::endl;
> std::abort(); /* Or trigger a breakpoint/test failure */
> }
> }
>
> What do you reckon?
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2026-07-01 06:31:18