select

Select one of two functions to run via template parameter.

  1. A select(A a, B b)
    A
    select
    (
    bool cond : true
    A
    B
    )
    (
    A a
    ,
    lazy B b
    )
  2. B select(A a, B b)

Parameters

cond

A bool which determines which function is run

a A

The first function

b B

The second function

Return Value

Type: A

a without evaluating b if cond is true. Otherwise, returns b without evaluating a.

Examples

real run() { return 0; }
int fail() { assert(0); }
auto a = select!true(run(), fail());
auto b = select!false(fail(), run());
static assert(is(typeof(a) == real));
static assert(is(typeof(b) == real));

Meta