Skip to content

Instantly share code, notes, and snippets.

@SingingBush
Last active January 6, 2023 18:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save SingingBush/3a2a6d2a41a81c1bafb26e5f69f823c0 to your computer and use it in GitHub Desktop.
Save SingingBush/3a2a6d2a41a81c1bafb26e5f69f823c0 to your computer and use it in GitHub Desktop.
a collection of D version checks for compatibility
// https://dlang.org/changelog/2.101.0.html#logger
static if(__traits(compiles, (){ import std.logger; } )) {
    import std.logger;
} else {
    // logger was in 'std.experimental' for a long time but you could optionally check that too
    import std.experimental.logger;
}
// https://dlang.org/changelog/2.099.0.html#checkedint
static if(__traits(compiles, (){ import std.checkedint; } )) {
    import std.checkedint;
} else {
    import std.experimental.checkedint; // support older D front ends
}
    // 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;
    // '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;
    }
    static if (__VERSION__ < 2080)
        import std.digest.digest : toHexString;
    else
        import std.digest : toHexString;
    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;
    }
    // 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;
    }
    // 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
@cschlote
Copy link

cschlote commented Jul 7, 2022

That's a cool collection.Really helpful stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment