| 1 |
// DISABLED: win32 win64 |
| 2 |
// EXTRA_CPP_SOURCES: cpp_stdlib.cpp |
| 3 |
// CXXFLAGS(osx linux freebsd openbsd netbsd dragonflybsd solaris): -std=c++11 |
| 4 |
import core.stdc.stdio; |
| 5 |
|
| 6 |
// Disabled on windows because it needs bindings |
| 7 |
|
| 8 |
version (CppRuntime_LLVM) |
| 9 |
{ |
| 10 |
extern(C++, `std`, `__1`) |
| 11 |
{ |
| 12 |
struct allocator(T); |
| 13 |
struct vector (T, A = allocator!T); |
| 14 |
struct array (T, size_t N); |
| 15 |
} |
| 16 |
} |
| 17 |
else |
| 18 |
{ |
| 19 |
extern(C++, `std`) |
| 20 |
{ |
| 21 |
struct allocator(T); |
| 22 |
struct vector (T, A = allocator!T); |
| 23 |
struct array (T, size_t N); |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
extern(C++): |
| 28 |
|
| 29 |
ref T identity (T) (ref T v); |
| 30 |
T** identityPP (T) (T** v); |
| 31 |
vector!T* getVector (T) (size_t length, const T* ptr); |
| 32 |
array!(T, N)* getArray(T, size_t N) (const T* ptr); |
| 33 |
|
| 34 |
void main () |
| 35 |
{ |
| 36 |
int i = 42; |
| 37 |
float f = 21.0f; |
| 38 |
|
| 39 |
int* pi = &i; |
| 40 |
float* pf = &f; |
| 41 |
|
| 42 |
assert(42 == identity(i)); |
| 43 |
assert(21.0f == identity(f)); |
| 44 |
assert(&pi == identityPP(&pi)); |
| 45 |
assert(&pf == identityPP(&pf)); |
| 46 |
|
| 47 |
auto vi = getVector(1, &i); |
| 48 |
auto vf = getVector(3, [f, f, f].ptr); |
| 49 |
assert(vi !is null); |
| 50 |
assert(vf !is null); |
| 51 |
|
| 52 |
auto ai = getArray!(int, 4)([2012, 10, 11, 42].ptr); |
| 53 |
auto af = getArray!(float, 4)([42.0f, 21.0f, 14.0f, 1957.0f].ptr); |
| 54 |
assert(ai !is null); |
| 55 |
assert(af !is null); |
| 56 |
|
| 57 |
printf("Success\n"); |
| 58 |
} |