Date: Tue, 13 Dec 2022 01:12:44 -0500
I propose that we introduce the following new preprocessor conditional
inclusion syntax:
condexpr if (expression or identifier, expression or identifier...) {
....the conditional logic....
}
New keyword to reserve: condexpr
Some advantages:
- The syntax looks more like standard C++ code and less like preprocessor
directives
- Rather than writing the preprocessor conditional inclusion syntax like
#ifdef and #endif at the beginning of each line, which breaks the flow of
code if the code is already nested, this syntax can be written directly
into the regular C++ code.
Here is how I would rewrite most of the example from the Conditional
Inclusion page here (
https://en.cppreference.com/w/cpp/preprocessor/conditional) using this new
syntax:
#define ABCD 2#include <iostream>
int main(){
condexpr if (ABCD)
{
std::cout <http://en.cppreference.com/w/cpp/io/cout> << "1: yes\n";
}else
{
std::cout <http://en.cppreference.com/w/cpp/io/cout> << "1: no\n";
} condexpr if (!ABCD)
{
std::cout <http://en.cppreference.com/w/cpp/io/cout> << "2: no1\n";
}elif (ABCD == 2)
{
std::cout <http://en.cppreference.com/w/cpp/io/cout> << "2: yes\n";
}else
{
std::cout <http://en.cppreference.com/w/cpp/io/cout> << "2: no2\n";
} condexpr if (!(DCBA) && (ABCD < 2*4-3))
{
std::cout <http://en.cppreference.com/w/cpp/io/cout> << "3: yes\n";
}
condexpr if (CPU)
{
std::cout <http://en.cppreference.com/w/cpp/io/cout> << "4: no1\n";
}elif (GPU)
{
std::cout <http://en.cppreference.com/w/cpp/io/cout> << "4: no2\n";
}elif (!RAM)
{
std::cout <http://en.cppreference.com/w/cpp/io/cout> << "4: yes\n";
}else
{
std::cout <http://en.cppreference.com/w/cpp/io/cout> << "4: no!\n";
}
}
inclusion syntax:
condexpr if (expression or identifier, expression or identifier...) {
....the conditional logic....
}
New keyword to reserve: condexpr
Some advantages:
- The syntax looks more like standard C++ code and less like preprocessor
directives
- Rather than writing the preprocessor conditional inclusion syntax like
#ifdef and #endif at the beginning of each line, which breaks the flow of
code if the code is already nested, this syntax can be written directly
into the regular C++ code.
Here is how I would rewrite most of the example from the Conditional
Inclusion page here (
https://en.cppreference.com/w/cpp/preprocessor/conditional) using this new
syntax:
#define ABCD 2#include <iostream>
int main(){
condexpr if (ABCD)
{
std::cout <http://en.cppreference.com/w/cpp/io/cout> << "1: yes\n";
}else
{
std::cout <http://en.cppreference.com/w/cpp/io/cout> << "1: no\n";
} condexpr if (!ABCD)
{
std::cout <http://en.cppreference.com/w/cpp/io/cout> << "2: no1\n";
}elif (ABCD == 2)
{
std::cout <http://en.cppreference.com/w/cpp/io/cout> << "2: yes\n";
}else
{
std::cout <http://en.cppreference.com/w/cpp/io/cout> << "2: no2\n";
} condexpr if (!(DCBA) && (ABCD < 2*4-3))
{
std::cout <http://en.cppreference.com/w/cpp/io/cout> << "3: yes\n";
}
condexpr if (CPU)
{
std::cout <http://en.cppreference.com/w/cpp/io/cout> << "4: no1\n";
}elif (GPU)
{
std::cout <http://en.cppreference.com/w/cpp/io/cout> << "4: no2\n";
}elif (!RAM)
{
std::cout <http://en.cppreference.com/w/cpp/io/cout> << "4: yes\n";
}else
{
std::cout <http://en.cppreference.com/w/cpp/io/cout> << "4: no!\n";
}
}
Received on 2022-12-13 06:12:59