var.opBinary

var opBinary(string op)(const var rhs) if (op == "+" || op == "-" || op == "*" || op == "/" || op == "%") const @safe

Binary arithmetic operators for var.

Supported operators: `+`, `-`, `*`, `/`, `%`

Type promotion rules:

  • If either operand is DOUBLE, FLOAT, or REAL, the result is DOUBLE.
  • If either operand is ULONG and the other is unsigned or fits, result is ULONG.
  • If either operand is LONG, result is LONG.
  • Otherwise, result is INT for smaller integer types.
  • For non-numeric types (NULL, STRING, ARRAY, OBJECT, CHAR, WCHAR, DCHAR, BOOL),

the operation returns var.init (NULL).

Parameters

opThe binary operator (`"+"`, `"-"`, `"*"`, `"/"`, `"%"`).
rhsThe right-hand side operand.

Returns

A new var containing the result of the operation, or var.init if the

operation is not supported for the given types.

Notes: Integer division/modulo by zero returns var.init (NULL) instead of silently yielding 0.

var opBinary(string op)(const var rhs) if (op == "~") const @safe

String concatenation operator for var.

Concatenates two var values as strings using the `~` operator. If either operand is a string, both operands are converted to their string representation and concatenated.

Parameters

rhsThe right-hand side operand.

Returns

A new var containing the concatenated string result.

Returns var.init (NULL) if neither operand is a string.

Examples

var a = "Hello";
var b = " World";
assert((a ~ b).as!string == "Hello World");

var num = 42;
assert(("Value: " ~ num).as!string == "Value: 42");