4 ms·
Did anyone reach out to you for input during the modules standardization process? D seems like the most obvious prior art, but the modules standardization proce
by Calavar 1y ago
Did anyone reach out to you for input during the modules standardization process? D seems like the most obvious prior art, but the modules standardization process seems like it was especially cursed
- WalterBright 1y agoNobody from C++ reached out to me for the modules. Herb Sutter, Andrei Alexandrescu and myself once submitted an official proposal for "static if" for C++, based on the huge success it has had in D. We received a vehement rejection. It demotivated me from submitting further proposals. ("static if" replaces the C preprocessor #if/#ifdef/#ifndef constructions.) C++ has gone on to adopt many features of D, but usually with modifications that make them less useful.
- jjmarr 1y agostatic if was more or less added in C++17 under the name `if constexpr`. It's not exactly the same since the discarded statement is still checked if not dependent on a template, but like most things in C++, it's similar enough to footgun yourself.
- sfpotter 1y ago"if constexpr" introduces a new scope, while "static if" does not. A major divergence, enough to make the features very, very different in terms of what they can actually be used for.
- WalterBright 1y agoThat was a giant mistake on C++'s part, as you cannot do this: static if (feature) { int bar() { betty(); }} ... lots of code ... static if (feature) bar(); Forcing a new scope cuts the utility of it about in half, and there's no way around it. But if you need a scope with D's static if: static if (expression) {{ int x; foo(x); }} the extra { } will do it. But, as it turns out, this is rarely desirable.
- jjmarr 1y agoI would use std::enable_if or C++20 concepts. Both work fine for selectively enabling functions.
- quotemstr 1y agoYes, but not for accommodating missing definitions or platform specific syntax. A true static if MUST allow invalid syntax in branches not taken if it's to fully replace the preprocessor.
- sfpotter 1y agoC++20 concepts are a step in the right direction, but: - D had this feature long before C++ did. - It isn't the same thing as "static if". Without "static if", conditionally compiling variables into classes is much more elaborate, basically requiring subclassing to do, which is not really semantically how subclassing should be used (the result is also way more confusing and oblique than the equivalent directly expressed construct you'd have using "static if").