Traits (The GNU D Compiler)

### 2.9 Traits ¶

Traits are extensions to the D programming language to enable programs, at compile time, to get at information internal to the compiler. This is also known as compile time reflection.

GNU D implements a `__traits(getTargetInfo)` trait that receives a string key as its argument. The result is an expression describing the requested target information.

    version (OSX)
    {
        static assert(__traits(getTargetInfo, "objectFormat") == "macho");
    }

Keys for the trait are implementation defined, allowing target-specific data for exotic targets. A reliable subset exists which a D compiler must recognize. These are documented by the D language specification hosted at https://dlang.org/spec/traits.html#getTargetInfo.

The following keys are recognized by GNU D.

`CET`

  When `-fcf-protection` is used, the first bit is set to 1 for the value `branch` and the second bit is set to 1 for the value `return`.

`cppRuntimeLibrary`

  The C++ runtime library affinity for this toolchain.

`cppStd`

  The version of the C++ standard supported by `extern(C++)` code, equivalent to the `__cplusplus` macro in a C++ compiler.

`floatAbi`

  Floating point ABI; may be ‘`hard`’, ‘`soft`’, or ‘`softfp`’.

`objectFormat`

  Target object format.