Date: Tue, 13 Dec 2022 11:29:06 -0500
Excellent point, that particular advantage I listed isn’t so compelling.
On Tue, Dec 13, 2022 at 1:20 AM Andrew Tomazos <andrewtomazos_at_[hidden]>
wrote:
> You can nest things as you like within #if. (Whitespace is not
> significant in C++.)
>
> On Tue, Dec 13, 2022 at 5:13 PM Michael Levine via Std-Proposals <
> std-proposals_at_[hidden]> wrote:
>
>> 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";
>> }
>>
>>
>>
>> }
>>
>> --
>> Std-Proposals mailing list
>> Std-Proposals_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>
>
On Tue, Dec 13, 2022 at 1:20 AM Andrew Tomazos <andrewtomazos_at_[hidden]>
wrote:
> You can nest things as you like within #if. (Whitespace is not
> significant in C++.)
>
> On Tue, Dec 13, 2022 at 5:13 PM Michael Levine via Std-Proposals <
> std-proposals_at_[hidden]> wrote:
>
>> 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";
>> }
>>
>>
>>
>> }
>>
>> --
>> Std-Proposals mailing list
>> Std-Proposals_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>
>
Received on 2022-12-13 16:29:19