On Friday, 26 July 2019 at 06:24:18 UTC, evilrat wrote:
On Friday, 26 July 2019 at 03:42:58 UTC, Andrey Zherikov wrote:
bool isModuleAvailable(alias modName)() {
mixin("import " ~ modName ~ ";");
static if (__traits(compiles, mixin(modName).stringof))
return true;
else
return false;
}
// use like this
static if (__traits(compiles, isModuleAvailable!"mymod" ))
import mymod;
I forgot the exact details but I ran into troubles with this
where __traits(compiles, moduleName) would evaluate to false even
if the module was available, if there were top-level errors in it.
I use __traits(compiles, __traits(identifier, moduleName)) now
instead and it seems to work.