byKeyValue is not available at compilation-time right ?

someone someone at somewhere.com
Sun Jul 25 05:10:32 UTC 2021


As you can see in the following code I cannot avoid to type the 
IDs twice in the structureExchanges enum:

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

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

}

/// implementation: exchange properties are «almost» immutable; 
eg: NYSE is (and will always be) on NY, USA trading in USD
/// implementation: from the app perspective (think integrity) 
giving the user read‐only exchange data is a plus … ie: don't 
mess with this
/// implementation: however, would it be possible to 
dynamically‐load the following enums from a file at 
compilation‐time ?

public immutable enum structureLocations = [
    r"BUE"d : typeLocation(r"arg"d, r"Buenos Aires"d, r"ART"d),
    r"GRU"d : typeLocation(r"bra"d, r"São Paulo"d, r"BRT"d),
    r"HHN"d : typeLocation(r"deu"d, r"Frankfurt am Main"d, 
r"CET"d),
    r"LHR"d : typeLocation(r"gbr"d, r"London"d, r"UTC"d),
    r"NYC"d : typeLocation(r"usa"d, r"New York"d, r"EST"d)
    ];

public immutable enum structureExchanges = [
    r"B3"d     : structureExchange(structureLocations[r"GRU"d], 
r"B3"d, r"B3 formerly Bolsa de Valores de São Paulo (aka 
BOVESPA)"d, r"BRL"d),
    r"BCBA"d   : structureExchange(structureLocations[r"BUE"d], 
r"BCBA"d, r"Bolsa de Comercio de Buenos Aires"d, r"ARS"d),
    r"LSE"d    : structureExchange(structureLocations[r"LHR"d], 
r"LSE"d, r"London Stock Exchange"d, r"GBP"d),
    r"NASDAQ"d : structureExchange(structureLocations[r"NYC"d], 
r"NASDAQ"d, r"National Association of Securities Dealers 
Automated Quotations"d, r"USD"d),
    r"NYSE"d   : structureExchange(structureLocations[r"NYC"d], 
r"NYSE"d, r"New York Stock Exchange"d, r"USD"d),
    r"XETRA"d  : structureExchange(structureLocations[r"HHN"d], 
r"XETRA"d, r"Deutsche Börse"d, r"EUR"d)
    ]; /// byKeyValue is not available at compile‐time; hence the 
redundancy of IDs
```

I attempted to use byKeyValue to get rid of the second set of IDs 
to no avail; eg:

```d
static foreach(
    structureExchange sudtExchange;
    structureExchanges.byKeyValue
    ) {

    ...  sudtExchange.key
    ...  sudtExchange.value

}
```


More information about the Digitalmars-d-learn mailing list