<div dir="ltr">also: catch D exceptions from C++ vs catching C++ exceptions from D; IIRC only one direction is supported</div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jan 30, 2017 at 11:42 AM, kinke via Digitalmars-d <span dir="ltr"><<a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I was wondering whether C++ interop is already considered sufficiently working enough, as I don't see any plans for improving it in the H1 2017 vision, except for the `C++ stdlib interface` bullet point.<br>
<br>
IMO, the main obstacles for mixed D/C++ RAII-style code are:<br>
<br>
1) Constructors don't work across the C++/D language barrier, as they are mangled differently and slightly differ in semantics (D ctors assume the instance is pre-initialized with T.init) => currently need to implement them on both sides. Additionally, D structs cannot have a non-disabled parameter-less constructor.<br>
2) Destructors need to be implemented on both sides as well.<br>
3) Copy/move constructors/assignment operators too.<br>
<br>
I think D could do a lot better. Constructors for example:<br>
<br>
// D<br>
extern(C++) struct T {<br>
  this(bool a); // declares C++ ctor T::T(bool)<br>
<br>
  extern(D) this(int a)<br>
  {<br>
    // Generates D ctor T::__ctor(int) and C++ ctor T::T(int).<br>
    // The C++ ctor is implemented as `{ this = T.init; this.__ctor(a); }`<br>
    // to initialize the memory allocated by C++ callers.<br>
    // D clients call the D __ctor directly to avoid double-initialization;<br>
    // that's what the extern(D) makes explicit.<br>
  }<br>
}<br>
<br>
// C++<br>
struct T {<br>
  T(bool a) {<br>
    // Callable from D; instance will be initialized twice then.<br>
  }<br>
<br>
  T(int a); // declares the C++ ctor wrapper emitted by the D compiler<br>
};<br>
<br>
Similarly, the D compiler could generate explicit C++ copy and move constructors automatically if the extern(C++) struct has an extern(D) postblit ctor, so that C++ clients only need to declare them. `extern(C++) this(this);` postblit ctor declarations could be used to make D clients call copy/move ctors implemented in C++ etc...<br>
</blockquote></div><br></div>