Comment #0 by bearophile_hugs — 2013-02-02T13:43:27Z
Array literals support the {} syntax to create structs, while associative array literals don't:
struct Foo { int x; }
void main() {
auto a1 = [Foo(10), Foo(20)]; // OK
Foo[] a2 = [{10}, {20}]; // OK
auto aa1 = [Foo(1): Foo(10), Foo(2): Foo(20)]; // OK
Foo[Foo] aa2 = [{1}: {10}, {2}: {20}]; // Line6, error
}
DMD 2.062alpha gives:
temp.d(6): Error: not an associative array initializer
That syntax is partially supported by Go language maps:
package main
import "fmt"
type Foo struct { x int }
func main() {
aa := map[int]Foo {1: {10}, 2: {20}}
fmt.Println(aa[2])
}
Comment #1 by razvan.nitu1305 — 2023-01-31T11:10:54Z
*** Issue 18611 has been marked as a duplicate of this issue. ***
Comment #2 by robert.schadek — 2024-12-13T18:03:54Z