View source code Display the source code in std/traits.d from which this page was generated on github. Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

std.traits.select - multiple declarations

Function select

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

Prototypes

A select(bool cond, A, B)(
  A a,
  B b
);

B select(bool cond, A, B)(
  A a,
  B b
);

Alias Select

Aliases itself to T[0] if the boolean condition is true and to T[1] otherwise.

Declaration

alias Select(bool condition, T...) = T[!condition];

Example

// can select types
static assert(is(Select!(true, int, long) == int));
static assert(is(Select!(false, int, long) == long));

// can select symbols
int a = 1;
int b = 2;
alias selA = Select!(true, a, b);
alias selB = Select!(false, a, b);
assert(selA == 1);
assert(selB == 2);
}

/**
If cond is true, returns a without evaluating b. Otherwise, returns b without evaluating a.
*/
A select(bool cond : true, A, B)(A a, lazy B b) { return a; 

Authors

Walter Bright, Tomasz Stachowiak (isExpressions), Andrei Alexandrescu, Shin Fujishiro, Robert Clipsham, David Nadlinger, Kenji Hara, Shoichi Kato

License

Boost License 1.0.

Comments