Issue 19495 - Lack of version conjunctions
Summary: Lack of version conjunctions
Status: RESOLVED DUPLICATE of issue 7417
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 enhancement
Assignee: No Owner
URL:
Keywords: spec
Depends on:
Blocks:
 
Reported: 2018-12-15 21:50 UTC by n4jm4
Modified: 2020-03-21 03:56 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description n4jm4 2018-12-15 21:50:04 UTC
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 anonymous4 2018-12-17 15:54:13 UTC
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 basile-z 2019-06-30 08:05:25 UTC
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 ***