1 module it.cpp.function_;
2 
3 import it;
4 
5 @("ref basic param")
6 unittest {
7     shouldCompile(
8         Cpp(
9             q{
10                 void fun(int& i);
11                 void gun(double& i);
12             }
13         ),
14         D(
15             q{
16                 int i;
17                 fun(i);
18                 static assert(!__traits(compiles, fun(4)));
19 
20                 double d;
21                 gun(d);
22                 static assert(!__traits(compiles, gun(33.3)));
23 
24             }
25         ),
26    );
27 }
28 
29 @("ref struct param")
30 unittest {
31     shouldCompile(
32         Cpp(
33             q{
34                 struct Foo { int i; double d; };
35                 void fun(Foo& f);
36             }
37         ),
38         D(
39             q{
40                 auto f = Foo(2, 33.3);
41                 fun(f);
42                 static assert(!__traits(compiles, fun(Foo(2, 33.3))));
43             }
44         ),
45    );
46 }
47 
48 
49 @("ref basic return")
50 unittest {
51     shouldCompile(
52         Cpp(
53             q{
54                 int& fun();
55                 double& gun();
56             }
57         ),
58         D(
59             q{
60                 auto i = fun();
61                 static assert(is(typeof(i) == int), typeof(i).stringof);
62 
63                 auto d = gun();
64                 static assert(is(typeof(d) == double), typeof(i).stringof);
65             }
66         ),
67    );
68 }
69 
70 @("ref struct return")
71 unittest {
72     shouldCompile(
73         Cpp(
74             q{
75                 struct Foo { int i; };
76                 Foo& fun();
77             }
78         ),
79         D(
80             q{
81                 auto f = fun();
82                 static assert(is(typeof(f) == Foo), typeof(i).stringof);
83             }
84         ),
85    );
86 }