Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> I really keep running into situations where a language that lives on top of C/C++ is useful. > the biggest advantage is being able to directly interface with any C or C++ natively. D/Rust both seem to have difficulty being 100% onboard with C++

I thought one of the centerpieces of D was seamless c++ interop? Where does it fall down?



You just need to do a bit of tiresome explicit declarations to statically link the code.

For libraries with a large API that can be an annoyance.


AFAICT, D requires the C++ types be exported, included any predefined template objects or functions. E.g. you can’t dynamically wrap `std::map<K,V>`, unless it’s already been instantiated in C++ library you’re linking. The same in Rust as well. See D Lang manual:

    Note that all instantiations used in D code must be provided by linking to C++ object code or shared libraries containing the instantiations. 
Whereas Nim is one of the few languageS that can dynamically wrap C++ template types into its type system. Maybe Zig can do it too? See Nim manual [2].

    type StdMap {.importcpp: "std::map", header: "<map>".}[K, V] = object proc
    ...
    var x: StdMap[cint, cdouble]
    x[6] = 91.4
    ...
    std::map<int, double> x;
    x[6] = 91.4;
This makes it nice to wrap C++ libraries. :-)

1: https://dlang.org/spec/cpp_interface.html#cpp-templates 2: https://nim-lang.org/docs/manual.html#importcpp-pragma-impor...


So, more than for using c++ with c++ -- in your build/link setup?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: