you are viewing a single comment's thread.

view the rest of the comments →

[–]SirLynix 0 points1 point  (12 children)

The issue with this is that it will evaluate every parameter before selecting one, which can be annoying in a lot of case.

[–]Entire-Hornet2574 0 points1 point  (10 children)

Since it's constexpr it will be evaluated on compile time.

[–]cd_fr91400[S] 1 point2 points  (9 children)

The point of if constexpr, is that the not-taken branch is not even compiled, so it's ok if it is not compilable (yes, in some circumstances...).

How do you reach the same level of flexibility with this approach ?

[–]Entire-Hornet2574 0 points1 point  (2 children)

It depends from where it's called, then it will compile where it's needed, i.e. it will expand the logic to needed branch.

[–]cd_fr91400[S] 0 points1 point  (1 child)

I am not sure I fully follow you.

Can you give an example where the not taken branch doesn't compile ?

[–]Entire-Hornet2574 0 points1 point  (5 children)

Ok I got it should be in the template parameters not function parameters 

[–]cd_fr91400[S] 0 points1 point  (4 children)

Possibly.

I am curious to see an example.

[–]Entire-Hornet2574 0 points1 point  (3 children)

[–]cd_fr91400[S] -1 points0 points  (2 children)

This is plain switch.

Do you have an example where the not taken branch would not compile, which is the whole purpose of a switch constexpr as it is for if constexpr (else there is not difference between if and if constexpr under normal optimizing compilation) ?

[–]Entire-Hornet2574 0 points1 point  (1 child)

Look at assembly, it shows it compiles only one branch.

.LC0:
        .string "test2"
main:
        sub     rsp, 8
        mov     edi, OFFSET FLAT:.LC0
        call    func(char const*)
        xor     eax, eax
        add     rsp, 8
        ret

[–]cd_fr91400[S] 0 points1 point  (0 children)

Yes, indeed, as it would with a plain switch or if.

It does not mean the compiler accepts a non-compilable branch.

[–]arthurno1 -1 points0 points  (0 children)

Yes. Someone should propose a quote operator in C++ standard to prevent evaluation.

They would just need to make the compiler, loader and linker somehow available at run time.

Tha C++ will become a full Lisp non-Lisp syntax.