[Issue 1598] New std.variant is missing functionality from Box

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Oct 19 15:58:32 PDT 2007


http://d.puremagic.com/issues/show_bug.cgi?id=1598





------- Comment #1 from andrei at metalanguage.com  2007-10-19 17:58 -------
This is by design.  The approach based on _arguments and _argptr loses static
type information. Variant needs that information in order to store a
type-dependent pointer to function. The approach confers Variant full
generality, unlike Box, which has to rely on exhaustive enumeration of a closed
set of types.

The feature can be added to Algebraic if needed, which in fact is very similar
in functionality with Boxer.

I am adding the following to Variant's documentation.

/*
 * Code that needs functionality similar to the $(D_PARAM boxArray)
 * function in the $(D_PARAM std.boxer) module can achieve it like this:
 *
 * ----
 * // old
 * Box[] fun(...)
 * {
 *     ...
 *     return boxArray(_arguments, _argptr);
 * }
 * // new
 * Variant[] fun(T...)(T args)
 * {
 *     ...
 *     return variantArray(args);
 * }
 * ----
 *
 * This is by design. During construction the $(D_PARAM Variant) needs
 * static type information about the type being held, so as to store a
 * pointer to function for fast retrieval.
*/


-- 



More information about the Digitalmars-d-bugs mailing list