SmartUnion

Provides a getter and setter method for each member of U. Additionally an "Active" enumerator and an "active" getter method is provided. The "Active" enumerator members copy the U member names, the values of that members start with 1. The "Active" enumerator has an additional "none" member with the value 0. The "active" getter method returns the "Active" enumerator value of the type currently set in the union -- this may be "none" if the union is in its initial state.

Members

Aliases

Active
alias Active = _.Active

Active enumerator type alias

Functions

active
Active active()
active_name
istring active_name()

Examples

union MyUnion
{
    int x;
    mstring y;
}

void main ( )
{
    SmartUnion!(MyUnion) u;
    istring name;
    u.Active a;             // u.Active is defined as
                            // `enum u.Active {none, x, y}`

    a = u.active;           // a is now a.none
    name = u.active_name;   // name is now "none"
    int b = u.x;            // error, u.x has not yet been set
    u.x   = 35;
    a = u.active;           // a is now a.x
    name = u.active_name;   // name is now "x"
    mstring c = u.y;        // error, u.y is not the active member
}

Meta