Bug 19495 – Lack of version conjunctions

Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-12-15T21:50:04Z
Last change time
2020-03-21T03:56:41Z
Keywords
spec
Assigned to
No Owner
Creator
andrew.pennebaker

Comments

Comment #0 by andrew.pennebaker — 2018-12-15T21:50:04Z
version() blocks often require combinations of version identifiers, including union, intersection, negation, else if, and else structures. However, D currently does not allow version expressions to be combined this way. When a programmer wants to write version(A) { ... } version(B) { ... } version(C || D) { ... } else { ... } D instead generates a compiler error, or unintended runtime behavior, or even different behavior based on the current host environment. I think it is reasonable to assume that programmers want to combine version identifiers much like if/else if/else structures, and we should offer this capability to our users.
Comment #1 by dfj1esp02 — 2018-12-17T15:54:13Z
Currently version statement is optimized for speed, you can have arbitrary logic with static if. --- template Defined(string s) { mixin(`version(`~s~`)enum Defined=true;else enum Defined=false;`); } struct SVersion { alias opDispatch(string s)=Defined!s; } enum Version=SVersion(); int main() { static if(Version.OSX)writeln("running OSX"); else writeln("no"); return 0; } ---
Comment #2 by b2.temp — 2019-06-30T08:05:25Z
This enhancement request but the language designers are not in favor of it. Anyway it was already opened : https://issues.dlang.org/show_bug.cgi?id=7417 *** This issue has been marked as a duplicate of issue 7417 ***