View source code
Display the source code in std/experimental/checkedint.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
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.

std.experimental.checkedint.Checked/checked - multiple declarations

Function checked

Convenience function that turns an integral into the corresponding Checked instance by using template argument deduction. The hook type may be specified (by default Abort).

Checked!(T,Hook) checked(Hook, T) (
  const T value
)
if (is(typeof(Checked!(T, Hook)(value))));

Example

static assert(is(typeof(checked(42)) == Checked!int));
writeln(checked(42)); // Checked!int(42)
static assert(is(typeof(checked!WithNaN(42)) == Checked!(int, WithNaN)));
writeln(checked!WithNaN(42)); // Checked!(int, WithNaN)(42)

Struct Checked

Checked integral type wraps an integral T and customizes its behavior with the help of a Hook type. The type wrapped must be one of the predefined integrals (unqualified), or another instance of Checked.

struct Checked(T, Hook)
  
if (isIntegral!T || is(T == Checked!(U, H), U, H));

Constructors

NameDescription
this (rhs) Constructor taking a value properly convertible to the underlying type. U may be either an integral that can be converted to T without a loss, or another Checked instance whose representation may be in turn converted to T without a loss.
this (str) Construct from a decimal string. The conversion follows the same rules as to converting a string to the wrapped T type.

Fields

NameTypeDescription
hook Hookhook is a member variable if it has state, or an alias for Hook otherwise.

Methods

NameDescription
get () Returns a copy of the underlying value.
opAssign (rhs) Assignment operator. Has the same constraints as the constructor.
opBinary (rhs) Defines binary operators +, -, *, /, %, ^^, &, |, ^, <<, >>, and >>>. If Hook defines hookOpBinary, opBinary forwards to Checked!(typeof(hook.hookOpBinary!op(get, rhs)), Hook)(hook.hookOpBinary!op(get, rhs)).
opBinaryRight (lhs) Defines binary operators +, -, *, /, %, ^^, &, |, ^, <<, >>, and >>> for the case when a built-in numeric or Boolean type is on the left-hand side, and a Checked instance is on the right-hand side.
opCast () Casting operator to integral, bool, or floating point type. If Hook defines hookOpCast, the call immediately returns hook.hookOpCast!U(get). Otherwise, casting to bool yields get != 0 and casting to another integral that can represent all values of T returns get promoted to U.
opCmp (rhs) Compares this against rhs for ordering. If Hook defines hookOpCmp, the function forwards to hook.hookOpCmp(get, rhs). Otherwise, the result of the built-in comparison operation is returned.
opEquals (rhs) Compares this against rhs for equality. If Hook defines hookOpEquals, the function forwards to hook.hookOpEquals(get, rhs). Otherwise, the result of the built-in operation get == rhs is returned.
opOpAssign (rhs) Defines operators +=, -=, *=, /=, %=, ^^=, &=, |=, ^=, <<=, >>=, and >>>=.
opUnary () Defines unary operators +, -, ~, ++, and --. Unary + is not overridable and always has built-in behavior (returns this). For the others, if Hook defines hookOpUnary, opUnary forwards to Checked!(typeof(hook.hookOpUnary!op(get)), Hook)(hook.hookOpUnary!op(get)).
toHash () Generates a hash for this. If Hook defines hookToHash, the call immediately returns hook.hookToHash(payload). If Hook does not implement hookToHash, but it has state, a hash will be generated for the Hook using the built-in function and it will be xored with the hash of the payload.
toString (sink, fmt) Writes a string representation of this to a sink.

Aliases

NameDescription
Representation The type of the integral subject to checking.

Authors

License