Head Const
Ola Fosheim Grøstad via Digitalmars-d
digitalmars-d at puremagic.com
Tue Feb 16 01:29:19 PST 2016
On Tuesday, 16 February 2016 at 09:04:48 UTC, Daniel Murphy wrote:
> I'm starting to think we should give up on implementing C++
> support in the language and move it to the library.
>
> eg
>
> mixin(cppFunctionBinding("unsigned long long
> NameSpace::myFunc(char * const && x, long double y)");
>
> expands to some combination of pragma(mangle) and extern(C++)
>
> With the limitation that only declarations can be parsed, it's
> not that bad to implement a ctfe C++ parser, and we can stop
> the creep of C++ features and hack into D.
>
> As a bonus, it could generate wrappers when we really can't
> match the semantics well enough.
I agree with the principle, but not as a library function,
because:
1. you want virtual functions to work out ok
2. making D more reliant on macroish string processing is not good
You would need something along the lines of:
1. «extern "C++"» the essence of the class definition in plain
C++ syntax
2. add to this syntax a translation for each parameter what it
means in D.
E.g.
extern "C++" {
class X {
mutable int rc;
virtual func1(const A* ptr); @reinterpret(ptr, head_const_ptr!A)
virtual func2(const A* ptr); @reinterpret(ptr, const A*)
virtual func3(A* ptr);
virtual func4(const A* ptr); @reinterpret(ptr, const_rc!A*)
};
}
More information about the Digitalmars-d
mailing list