Fastest way to check using if identifier has already been defined, using static if or similar?
drathier
forum.dlang.org at fi.fo
Thu Jun 4 17:28:06 UTC 2020
On Wednesday, 3 June 2020 at 09:03:22 UTC, drathier wrote:
> I'm generating some code. Some of the generated types need to
> be overridden, so I define them manually at the top of the
> generated file. Then I need to guard against redefining the
> identifier (type/value/function) later on, in the generated
> code.
>
> I'm currently using `static if (!__traits(compiles, thingy)) {`
> to avoid redefining things twice.
>
> Of course the proper fix is to not generate code for the
> identifiers which are already manually defined, and not
> generate any `static if`s at all, but until then, is there a
> faster way than `static if (__traits(compiles, ...` to check if
> a type/value/function has already been defined?
This seems more complicated than I initially assumed. Is there a
faster way if we separate the question to find just one of types,
templates or top-level values at a time, into three different
solutions? The definitions and static ifs are always always top
level definitions/statements in my case.
More information about the Digitalmars-d-learn
mailing list