Date: Tue, 30 Jun 2026 15:41:00 +0100
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?
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?
Received on 2026-06-30 14:41:14
