| 1 |
extern "C" int printf(const char *, ...); |
| 2 |
|
| 3 |
#define Foo(T) \ |
| 4 |
T fooD(T param); \ |
| 5 |
T fooCpp(T param) \ |
| 6 |
{ \ |
| 7 |
printf("fooCpp %d [%p]\n", param.a, ¶m); \ |
| 8 |
return fooD(T{2 * param.a}); \ |
| 9 |
} |
| 10 |
|
| 11 |
struct POD |
| 12 |
{ |
| 13 |
int a; |
| 14 |
}; |
| 15 |
Foo(POD); |
| 16 |
|
| 17 |
struct CtorOnly |
| 18 |
{ |
| 19 |
int a; |
| 20 |
CtorOnly() : a(0) {} |
| 21 |
CtorOnly(int a) : a(a) {} |
| 22 |
}; |
| 23 |
Foo(CtorOnly); |
| 24 |
|
| 25 |
struct DtorOnly |
| 26 |
{ |
| 27 |
int a; |
| 28 |
~DtorOnly(); // implemented in D |
| 29 |
}; |
| 30 |
Foo(DtorOnly); |
| 31 |
|
| 32 |
struct CtorDtor |
| 33 |
{ |
| 34 |
int a; |
| 35 |
CtorDtor(int a) : a(a) {} |
| 36 |
~CtorDtor(); // implemented in D |
| 37 |
}; |
| 38 |
Foo(CtorDtor); |
| 39 |
|
| 40 |
struct Copy |
| 41 |
{ |
| 42 |
int a; |
| 43 |
Copy(int a) : a(a) {} |
| 44 |
~Copy(); // implemented in D |
| 45 |
Copy(const Copy &rhs) : a(rhs.a) { printf("cppcpy %d [%p]\n", a, this); } |
| 46 |
}; |
| 47 |
Foo(Copy); |
| 48 |
|
| 49 |
struct CopyAndMove |
| 50 |
{ |
| 51 |
int a; |
| 52 |
CopyAndMove(int a) : a(a) {} |
| 53 |
~CopyAndMove(); // implemented in D |
| 54 |
CopyAndMove(const CopyAndMove &rhs) : a(rhs.a) { printf("cppcpy %d [%p]\n", a, this); } |
| 55 |
CopyAndMove(CopyAndMove &&) = default; |
| 56 |
}; |
| 57 |
Foo(CopyAndMove); |
| 58 |
|
| 59 |
struct MoveOnly |
| 60 |
{ |
| 61 |
int a; |
| 62 |
MoveOnly(int a) : a(a) {} |
| 63 |
~MoveOnly(); // implemented in D |
| 64 |
MoveOnly(const MoveOnly &) = delete; |
| 65 |
MoveOnly(MoveOnly &&) = default; |
| 66 |
}; |
| 67 |
Foo(MoveOnly); |
| 68 |
|
| 69 |
struct MemberWithCtor |
| 70 |
{ |
| 71 |
int a; |
| 72 |
CtorOnly m; |
| 73 |
}; |
| 74 |
Foo(MemberWithCtor); |