to

Converts from to a boolean.

If From is a numeric type, then 1 becomes $(D_KEYWORD true), 0 $(D_KEYWORD false). Otherwise $(D_PSYMBOL ConvException) is thrown.

If To is a string (built-in string or $(D_PSYMBOL String)), then "true" or "false" are converted to the appropriate boolean value. Otherwise $(D_PSYMBOL ConvException) is thrown.

Parameters

From

Source type.

To

Target type.

from From

Source value.

Return Value

Type: To

$(D_KEYWORD from) converted to a boolean.

Throws

$(D_PSYMBOL ConvException) if from isn't convertible.

Examples

assert(!0.0.to!bool);
assert(0.2.to!bool);
assert(0.5.to!bool);
assert(1.0.to!bool);

assert(!0.to!bool);
assert(1.to!bool);
assert("true".to!bool);
assert(!"false".to!bool);
assert(String("true").to!bool);
assert(!String("false").to!bool);

Meta