How to check that import module will succeed?

2019-07-25 Thread Andrey Zherikov via Digitalmars-d-learn
Is there a way to check whether some module, say "foo", is available for import before doing "import foo"? I want to create a function that imports module if it's available or does something else otherwise. So I think the code should look something like this: mixin template my_import(alias mod

Re: How to check that import module will succeed?

2019-07-25 Thread evilrat via Digitalmars-d-learn
On Friday, 26 July 2019 at 03:42:58 UTC, Andrey Zherikov wrote: Is there a way to check whether some module, say "foo", is available for import before doing "import foo"? I did some really retarded utility like this in the past, worked for me, but I can't say it is that well tested and there m

Re: How to check that import module will succeed?

2019-07-26 Thread Anonymouse via Digitalmars-d-learn
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;

Re: How to check that import module will succeed?

2019-07-26 Thread Paul Backus via Digitalmars-d-learn
On Friday, 26 July 2019 at 03:42:58 UTC, Andrey Zherikov wrote: Is there a way to check whether some module, say "foo", is available for import before doing "import foo"? I want to create a function that imports module if it's available or does something else otherwise. So I think the code shou

Re: How to check that import module will succeed?

2019-07-26 Thread Andrey Zherikov via Digitalmars-d-learn
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: Is there a way to check whether some module, say "foo", is available for import before doing "import foo"? I did some really retarded utility like this in the past, worked f

Re: How to check that import module will succeed?

2019-07-26 Thread Andrey Zherikov via Digitalmars-d-learn
On Friday, 26 July 2019 at 14:14:11 UTC, Anonymouse wrote: I use __traits(compiles, __traits(identifier, moduleName)) now instead and it seems to work. I couldn't find "identifier" docs on https://dlang.org/phobos/std_traits.html. But I tried and it doesn't work - I think because is unknown

Re: How to check that import module will succeed?

2019-07-26 Thread Andrey Zherikov via Digitalmars-d-learn
On Friday, 26 July 2019 at 14:19:05 UTC, Paul Backus wrote: version(HasStdio) import std.stdio; else pragma(msg, "std.stdio is not available"); Then configure your build system to pass `-version=HasStdio` to dmd (or the equivalent flag to ldc or gdc) when std.stdio is available. I wa

Re: How to check that import module will succeed?

2019-07-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 26 July 2019 at 03:42:58 UTC, Andrey Zherikov wrote: Is there a way to check whether some module, say "foo", is available for import before doing "import foo"? static if (is(typeof((){import that.module.here;}))) { // it is available }

Re: How to check that import module will succeed?

2019-07-26 Thread evilrat via Digitalmars-d-learn
On Friday, 26 July 2019 at 14:56:37 UTC, Andrey Zherikov wrote: Even without static if I get the same result: mixin template my_import(alias modName) { mixin("import " ~ modName ~ ";"); } mixin my_import!"mymod"; pragma(msg,fullyQualifiedName!(myfunc)); // Error: undefined identifier