std.boxer
This module is a set of types and functions for converting any object (value or heap) into a generic box type, allowing the user to pass that object around without knowing what's in the box, and then allowing him to recover the value afterwards.

Example:

// Convert the integer 45 into a box.
Box b = box(45);

// Recover the integer and cast it to real.
real r = unbox!(real)(b);

That is the basic interface and will usually be all that you need to understand. If it cannot unbox the object to the given type, it throws UnboxException. As demonstrated, it uses implicit casts to behave in the exact same way that static types behave. So for example, you can unbox from int to real, but you cannot unbox from real to int: that would require an explicit cast.

This therefore means that attempting to unbox an int as a string will throw an error instead of formatting it. In general, you can call the toString method on the box and receive a good result, depending upon whether std.string.format accepts it.

Boxes can be compared to one another and they can be used as keys for associative arrays.

There are also functions for converting to and from arrays of boxes.

Example:

// Convert arguments into an array of boxes.
Box[] a = boxArray(1, 45.4, "foobar");

// Convert an array of boxes back into arguments.
TypeInfo[] arg_types;
void* arg_data;

boxArrayToArguments(a, arg_types, arg_data);

// Convert the arguments back into boxes using a
// different form of the function.
a = boxArray(arg_types, arg_data);

One use of this is to support a variadic function more easily and robustly; simply call "boxArray(_arguments, _argptr)", then do whatever you need to do with the array.

Authors:
Burton Radons

License:
Public Domain

Bugs: