std.variant holding bigger structs and std.concurrency message limitation
Idan Arye
GenericNPC at gmail.com
Sat Apr 27 10:42:52 PDT 2013
On Saturday, 27 April 2013 at 11:37:38 UTC, Tavi Cacina wrote:
> is it a bug the fact that a Variant may be initialized with a
> struct bigger than 32 bytes? Even if this does function, it is
> not consistent because you can not assign such an 'inflated'
> variant to another one, assertion. This affects the max size of
> a std.concurrency message (right now it is not specified that
> such restriction exists)
>
> ---
> import std.variant;
>
> struct S
> {
> int[9] s;
> }
>
> void main()
> {
> Variant v1, v2; // maximum size 32 bytes
> v1 = S(); // works, even if sizeof(S) > 32
> v2 = v1; // AssertError: target must be non-null
> }
> ---
There used to be a maximum size check for placing things in
variants, but it was removed back in 2009:
https://github.com/D-Programming-Language/phobos/commit/0c142994d9b5cb9f379eca28f3a625c749370e4a#L20L189
The way it works now, is that if the size is too big they use a
reference instead:
https://github.com/D-Programming-Language/phobos/blob/master/std/variant.d#L544#L555
More information about the Digitalmars-d
mailing list