H1 2015 - C++ integration
Guillaume Chatelet via Digitalmars-d
digitalmars-d at puremagic.com
Fri Feb 13 04:23:57 PST 2015
I'm working on integration of D with the C++ STL (at least the
linux gnu one).
* You can have a look at a current draft implementation (1).
* There is a name mangling issue in dmd related to the
compression of usual stl types when the type is const
eg. dmd will mangle 'std::vector<int>::size() const' as
'_ZNK3std6vectorIiSaIiEE4sizeEv' where it should be mangled
'_ZNKSt6vectorIiSaIiEE4sizeEv'. Note 'std' is being compressed
into 'St'.
I believe this is coming from
https://github.com/D-Programming-Language/dmd/blob/master/src/cppmangle.c#L453
which tests only the non const type pattern.
According to (2) this substitution seems illegal "Note that
substitutable components are the represented symbolic constructs,
not their associated mangling character strings."
This lead to undefined reference when linking and that's why my
code overrides the name mangling.
* In the video Walter posted recently (3), he states that one
should use a class to represent a std::string or std::vector in D
because most of the time we want to have reference semantic. I
find this a bit counter intuitive for people coming from C++
since they are clearly value semantic. std::string and
std::vector should behave the same in C++ and D to confirm the
principle of least astonishment.
I started implementing them as struct (4) but then I can only
have @disable default constructors.
I would like to gather opinions on struct vs class. Any ideas ?
Guillaume
---
1. https://github.com/gchatelet/dlang_cpp_std
2.
http://mentorembedded.github.io/cxx-abi/abi.html#mangling-compression
3. https://www.youtube.com/watch?v=IkwaV6k6BmM
4.
https://github.com/gchatelet/dlang_cpp_std/blob/master/std_string.d
More information about the Digitalmars-d
mailing list