how to test (at compilation-time) for existence of an already-declared object ?

someone someone at somewhere.com
Sat Jul 24 01:29:26 UTC 2021


Suppose I have a module with the following:

```d
public class classTickerCustomNYSE : classTickerCommon { ... }
public class classTickerCustomNASDAQ : classTickerCommon { ... }
```

... and given that I also have the following in the same module:

```d
public enum structureExchanges = [
    r"NYSE"d   : structureExchange(r"NYSE"d, r"New York Stock 
Exchange"d, r"USD"d, r"usa"d, r"New York"d, r"EST"d),
    r"NASDAQ"d : structureExchange(r"NASDAQ"d, r"National 
Association of Securities Dealers Automated Quotations"d, 
r"USD"d, r"usa"d, r"New York"d, r"EST"d),
    r"LSE"d    : structureExchange(r"LSE"d, r"London Stock 
Exchange"d, r"GBP"d, r"gbr"d, r"London"d, r"UTC"d),
    r"XETRA"d  : structureExchange(r"XETRA"d, r"Deutsche Börse"d, 
r"EUR"d, r"deu"d, r"Frankfurt am Main"d, r"CET"d),
    r"B3"d     : structureExchange(r"B3"d, r"B3 formerly Bolsa de 
Valores de São Paulo (aka BOVESPA)"d, r"BRL"d, r"bra"d, r"São 
Paulo"d, r"BRT"d),
    r"BCBA"d   : structureExchange(r"BCBA"d, r"Bolsa de Comercio 
de Buenos Aires"d, r"ARS"d, r"arg"d, r"Buenos Aires"d, r"ART"d)
    ];

public struct structureExchange { /// solely‐intended to help 
build code at compilation‐time; for client‐code classExchanges 
should be used instead

    public dstring ID;
    public dstring name;
    public dstring currencyID;
    public typeLocation location;

    @safe this(
       const dstring lstrExchangeID,
       const dstring lstrExchangeName,
       const dstring lstrCurrencyID,
       const dstring lstrCountryID,
       const dstring lstrCity,
       const dstring lstrTZ
       ) {

       ID = lstrExchangeID;
       name = lstrExchangeName;

       currencyID = lstrCurrencyID;

       location = typeLocation(
          lstrCountryID,
          lstrCity,
          lstrTZ)
          ;

    }

}
```

... at compilation-time I can do things like:

```d
static foreach (structureExchange sudtExchange; 
structureExchanges) { /// assume the following code as a template 
to build new classTickerCustom{ExchangeID} classes

    mixin(format!

       ` /// code chunk

       final public class classTickerCustom%1$s : 
classTickerCommon {

       ...

       }

       `(sudtExchange.ID) /// code chunk

    ); /// mixin ending

}
```

... now, question is: how can I check, within the static foreach 
code, whether a class is already-implemented or not; eg:

```d

static foreach (structureExchange sudtExchange; 
structureExchanges) {

    if (! ? == r"classTickerCustom"d ~ sudtExchange.ID) {

       /// class is not implemented yet: do whatever here ...

    }

}
```

... my first thought was traits 
(https://dlang.org/spec/traits.html) but I don't see anything 
useful there; there is getMember() but the example is for 
already-declared objects within the module, and not the module 
itself.


More information about the Digitalmars-d-learn mailing list