callWithActive

Calls the specified callable with the active field of the provided smart-union. If no field is active, does nothing.

Note: declared at module-scope (rather than nested inside the SmartUnion template) to work around limitations of template alias parameters. (Doing it like this allows it to be called with a local name.)

void
callWithActive
(
alias Callable
SU
)

Parameters

Callable

alias for the thing to be called with the active member of the provided smart-union

SU

type of smart-union to operate on

smart_union SU

smart-union instance whose active field should be passed to Callable

Examples

union TestUnion
{
    int a;
    float b;
}
alias SmartUnion!(TestUnion) TestSmartUnion;

static struct ActiveUnionFieldPrinter
{
    static void print ( T ) ( T t )
    {
        Stdout.formatln("{}", t);
    }

    void printActiveUnionField ( )
    {
        TestSmartUnion su;
        su.a = 23;
        callWithActive!(print)(su);
    }
}

Meta