Bug 1598 – New std.variant is missing functionality from Box
Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D1 (retired)
Platform
All
OS
All
Creation time
2007-10-19T17:39:00Z
Last change time
2014-02-24T16:00:01Z
Assigned to
andrei
Creator
aarti
Comments
Comment #0 by aarti — 2007-10-19T17:39:27Z
1. Converting variadic arguments to function:
Below was possible to achieve with Box.
# void func(...) {
# Box[] barr = boxArray(_arguments, _argptr);
# }
As I see there is not such a possibility in new Variant.
2. Possibility to assign variant type into variant.
Example:
# Variant a, b;
# a = 5;
# b = a;
# writefln(b.type);
std.boxer has functionality to store 'Variable of type Box inside other variable of type Box'. Currently probably it is not possible or at least it is not enough documented how to achieve this.
Comment #1 by andrei — 2007-10-19T17:58:31Z
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.
*/