std.boxer and arrays

Aarti_pl aarti at interia.pl
Wed Oct 17 01:57:30 PDT 2007


> You know.. the compiler and libraries are easily downloadable for you to 
> play and test yourself...
> 
> In that example, b is declared as a Variant si it's a Variant.  After 
> the assignment, b contains a copy of a since Variant is a typedef to a 
> templated struct.
> 
> The usage for variantArray is shown in the examples and I've included 
> one here for you as well.
> 
> $ cat /tmp/foo.d
> import std.stdio;
> import std.variant;
> 
> void main()
> {
>     Variant a;
>     a=5;
> 
>     Variant b;
>     b=a;
> 
>     writeln("a = ", a);
>     writeln("b = ", b);
> 
>     Variant[] c;
>     c = variantArray(1, 2, 3.1, 4);
>     writeln("c = ", c);
> }
> 
> $ /tmp/foo
> a = 5
> b = 5
> c = [1 2 3.1 4]
> 
> Later,
> Brad

Sorry Brad, but is my English really so bad, that you seem to completely 
not understand what I meant with my questions?

Please read a little bit more carefully, as you answer neither of both 
questions...

*Question 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. Or is it 
possible somehow? It's not question about making array of different 
values, but about converting variadic arguments to function into array 
of variants, what was possible with Box. Currently it seems that this 
(sometimes useful) functionality is missing from Variant.

*Question 2*
Possibility to assign variant type into variant.
Once again example:

# Variant a, b;
# a = 5;
# b = a;
# writefln(b.type);

the result is 'int', although I would like to get 'Variant'. Is it 
possible to achieve such a behavior, that I put Variant type into other 
Variant type? (So Variant will be 'boxed' in variant) With Box it was 
possible...

(I thought that using explicitly opAssign on b will allow this, but it 
seems that it behaves exactly same way as normal assignment; it is very 
good IMHO, as it is at least consistent).

BR
Marcin



More information about the Digitalmars-d mailing list