environment.opBinaryRight

Identify whether a variable is defined in the environment.

Because it doesn't return the value, this function is cheaper than get. However, if you do need the value as well, you should just check the return of get for null instead of using this function first.

class environment
static @trusted
bool
opBinaryRight
(
string op : "in"
)
(
scope const(char)[] name
)

Examples

// good usage
if ("MY_ENV_FLAG" in environment)
    doSomething();

// bad usage
if ("MY_ENV_VAR" in environment)
    doSomething(environment["MY_ENV_VAR"]);

// do this instead
if (auto var = environment.get("MY_ENV_VAR"))
    doSomething(var);

Meta