int => struct cast
Max Samukha
samukha at voliacable.com.removethis
Fri Oct 3 10:16:12 PDT 2008
On Thu, 02 Oct 2008 10:04:18 -0400, bearophile
<bearophileHUGS at lycos.com> wrote:
>Why can't I cast an n int to a struct with only a x int field?
>Time ago someone has said that all internal errors are problems, is this known and bad?
>
>struct S { int x; }
>void main() {
> int n = 1;
> int[S] a;
> a[ cast(S)n ]++;
>}
>
>OUTPUT DMD 1.035:
>temp.d(5): Error: e2ir: cannot cast from int to S
>Internal error: e2ir.c 3904
>
>Bye,
>bearophile
There is a not well documented feature that turns cast(S)n into S(n),
if opCall is defined
struct S {
int x;
static S opCall(int x) { S r; r.x = x; return r; }
}
void main() {
int n = 1;
int[S] a;
a[ cast(S)n ]++;
}
More information about the Digitalmars-d-learn
mailing list