Storing arrays as Variant types.
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Dec 23 15:22:45 PST 2014
Minimal code for convenience to others:
import std.variant;
void main()
{
Variant aVariant;
Variant bVariant;
char[] a = aVariant.coerce!(char[]);
byte[] b = bVariant.coerce!(byte[]);
}
On 12/23/2014 02:57 PM, Winter M. wrote:
> I've run into a problem while trying to coerce array values from a
> variant; specifically,
>
> char[] a = aVariant.coerce!(char[]); // This works just fine.
>
> byte[] b = bVariant.coerce!(byte[]); // This causes a static assertion
> to fail.
>
> I'm not really sure why a byte[] would be an unsupported type, since
> memory-wise the reference should take up as much space as for the char[]
> (as I understand it).
> Perhaps I'm missing something, but I'm lost as to why this is the case.
The difference is that char[] passes the isSomeString test (as it is a
string) but byte[] does not:
https://github.com/D-Programming-Language/phobos/blob/master/std/variant.d#L877
Ali
More information about the Digitalmars-d-learn
mailing list