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

Reply via email to