v2 / vlib / v / tests / comptime / comptime_generic_test.v
38 lines · 34 sloc · 625 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1fn test_comptime_generic() {
2 a := [5]int{}
3 func1(&a)
4}
5
6@[inline]
7pub fn func1[T](t &T) {
8 func2[T](t)
9}
10
11@[inline]
12pub fn func2[T](t &T) {
13 $if T is $array {
14 unsafe {
15 for i in 0 .. t.len {
16 func2(&t[i])
17 }
18 }
19 } $else $if T is $map {
20 // fake_map(t, df)
21 } $else $if T is $struct {
22 $for f in T.fields {
23 $if f.typ is string {
24 }
25 // Dummy expression to generate and specify t.$(f.name)'s type
26
27 // mut attrs := get_attrs(t.$(f.name), f)
28
29 // if !attrs.skip() {
30 // fake_data_wdf(&(t.$(f.name)))
31 // }
32 }
33 } $else {
34 unsafe {
35 // *t = fake_primitive_value<T>(df) or { panic(err) }
36 }
37 }
38}
39