The OpenD Programming Language

CmpTimeUnits

Compares two time unit strings at compile time. "years" are the largest units and "hnsecs" are the smallest.

This template is used instead of cmpTimeUnits because exceptions can't be thrown at compile time and cmpTimeUnits must enforce that the strings it's given are valid time unit strings. This template uses a template constraint instead.

template CmpTimeUnits (
string lhs
string rhs
) if (
validTimeUnits(lhs, rhs)
) {
enum CmpTimeUnits;
}

Return Value

this < rhs< 0
this == rhs0
this > rhs> 0

Examples

static assert(CmpTimeUnits!("years", "weeks") > 0);
static assert(CmpTimeUnits!("days", "days") == 0);
static assert(CmpTimeUnits!("seconds", "hours") < 0);

Meta