Skip to content

Instantly share code, notes, and snippets.

@cschlote
Forked from SingingBush/dlang_version_check.md
Created July 8, 2022 09:12
Show Gist options
  • Save cschlote/403abcfd8c097b7318b18355fa91feab to your computer and use it in GitHub Desktop.
Save cschlote/403abcfd8c097b7318b18355fa91feab to your computer and use it in GitHub Desktop.
a collection of D version checks for compatibility
    static if (__VERSION__ < 2074) {
        import std.traits : FieldTypeTuple, Filter; // Filter used to be in std.traits
    } else {
        import std.traits : FieldTypeTuple;
        import std.meta : Filter;
    }
    // 'std.exception.enforceEx' was deprecated in 2.080 and will be removed with 2.089,
    // use std.exception.enforce instead
    // https://dlang.org/changelog/2.080.0.html#std-exception-enforceEx
    static if(__VERSION__ >= 2080) {
        alias enforce = std.exception.enforce;
    } else {
        alias enforce = std.exception.enforceEx;
    }
    // In dmd 2.052, the module std.datetime was introduced. It will be replacing std.date entirely.
    // https://dlang.org/articles/intro-to-datetime.html
    static if(__traits(compiles, (){ import std.datetime.date; } )) {
        import std.datetime.date;
    }
    // std.experimental.logger has been around for a while but still best to check
    static if(__traits(compiles, (){ import std.experimental.logger; } )) {
        import std.experimental.logger;
    }
    // https://dlang.org/changelog/2.075.0.html#split-std-datetime
    static if (__VERSION__ >= 2077)
        import std.datetime.stopwatch : StopWatch; // uses core.time.Duration
    else
        import std.datetime : StopWatch; // uses core.time.TickDuration
    static if (__VERSION__ < 2080)
        import std.digest.digest : toHexString;
    else
        import std.digest : toHexString;
    // JSON_TYPE is now JSONType simply due to code style: https://issues.dlang.org/show_bug.cgi?id=19135
    static if(__VERSION__ >= 2082)
        import std.json : JSONType;
    else
        alias JSONType = std.json.JSON_TYPE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment