I'm part of the compiler team and have been working on the C++ interop this summer, to interact with a piece of C++ code written in modern C++14.
C++ is very well supported by D, in fact it probably has one of the best support for it out there, for a language of this size. You can, for example, throw any exception derived from std::exception
in C++ and catch it on the D side. You can write a class in D and use it from D (virtual method or not), or the other way around. You can subclass a D class from C++, and you can subclass a C++ class from D. You can call instantiated templated functions!
Now, there are a few catches:
- If you are doing something not very idiomatic in C++, e.g. throwing int, that's going to be a problem.
- The C++ code should not break D's type system. E.g. you cannot represent a
char* const*
(pointer to constant pointer to mutable char) because D's const is transitive, so it has to be const char* const*
.
- The cross-version support is still not optimal. There is currently a mix of C++98 and C++11, and no way to control what to use. It does not matter in 95% of the cases, since D interfaces at the binary level, and is only concerned about calling convention and symbol mangling.
As for platforms, Windows is very well supported (we have some game devs using it). POSIX support for calling templated functions is more recent, but works for me.
That's it for the language support. The tools around it (e.g. what Dejan mentioned) are still being built, and there's a big interest from the industry in having them, as D is regarded as much more pleasant to use, and it can offer an easy transition path for C++ developers. In fact, all 3 D compilers (DMD, GDC, LDC) use a common frontend written in D, and exposed to C++ their backend (DMC, GCC, LLVM, respectively).
TL;DR:
- If you want to call C++ and can spare the time to write some bindings in D for your classes / functions, yes.
- If you cannot write the bindings, stay tuned.
- If you want to expose D code to C++, a resounding yes!