www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - C++ Interop

reply qznc <qznc web.de> writes:
I'm exploring [0] C++ interop after watching Walter's 
presentation [1].

I hit a block with classes as template parameters. This means 
vector<int> works, but vector<Foo> does not. D seems to map 
vector!Foo to vector<Foo*>. Likewise shared_ptr<Foo> is a 
problem. Any way to fix that on the D side? The ugly workaround 
is to adapt the C++ code.

I understand that this mapping makes sense for function calls 
because bar(Foo f) in D maps to bar(Foo *f) in C++. And C++ 
bar(Foo f) has no equivalent in D because classes are reference 
types.

On a related note, C++ interop requires to redeclare or even 
reimplement C++ code. Has anybody started a libcpp-in-d project? 
I'm looking for basics like vector and string.

[0] https://github.com/qznc/d-cpptest
[1] https://youtu.be/IkwaV6k6BmM
Jan 05 2018
next sibling parent Timothee Cour <thelastmammoth gmail.com> writes:
see also https://github.com/Syniurge/Calypso/ although I'm having lots
of issues using it on OSX

On Fri, Jan 5, 2018 at 9:02 AM, qznc via Digitalmars-d-learn
<digitalmars-d-learn puremagic.com> wrote:
 I'm exploring [0] C++ interop after watching Walter's presentation [1].

 I hit a block with classes as template parameters. This means vector<int>
 works, but vector<Foo> does not. D seems to map vector!Foo to vector<Foo*>.
 Likewise shared_ptr<Foo> is a problem. Any way to fix that on the D side?
 The ugly workaround is to adapt the C++ code.

 I understand that this mapping makes sense for function calls because
 bar(Foo f) in D maps to bar(Foo *f) in C++. And C++ bar(Foo f) has no
 equivalent in D because classes are reference types.

 On a related note, C++ interop requires to redeclare or even reimplement C++
 code. Has anybody started a libcpp-in-d project? I'm looking for basics like
 vector and string.

 [0] https://github.com/qznc/d-cpptest
 [1] https://youtu.be/IkwaV6k6BmM
Jan 05 2018
prev sibling next sibling parent reply Seb <seb wilzba.ch> writes:
On Friday, 5 January 2018 at 13:02:12 UTC, qznc wrote:
 I'm exploring [0] C++ interop after watching Walter's 
 presentation [1].

 [...]
I know about this: https://github.com/Remedy-Entertainment/binderoo https://github.com/dlang/druntime/pull/1802
Jan 06 2018
next sibling parent reply Seb <seb wilzba.ch> writes:
On Saturday, 6 January 2018 at 11:17:56 UTC, Seb wrote:
 On Friday, 5 January 2018 at 13:02:12 UTC, qznc wrote:
 I'm exploring [0] C++ interop after watching Walter's 
 presentation [1].

 [...]
I know about this: https://github.com/Remedy-Entertainment/binderoo https://github.com/dlang/druntime/pull/1802
And: https://github.com/dlang/druntime/pull/1316 Also I think Ian ( ibuclaw) and Razvan7 are currently working on a header generation tool from D sources to C++ headers.
Jan 06 2018
parent reply qznc <qznc web.de> writes:
On Saturday, 6 January 2018 at 11:20:01 UTC, Seb wrote:
 On Saturday, 6 January 2018 at 11:17:56 UTC, Seb wrote:
 On Friday, 5 January 2018 at 13:02:12 UTC, qznc wrote:
 I'm exploring [0] C++ interop after watching Walter's 
 presentation [1].

 [...]
I know about this: https://github.com/Remedy-Entertainment/binderoo https://github.com/dlang/druntime/pull/1802
And: https://github.com/dlang/druntime/pull/1316 Also I think Ian ( ibuclaw) and Razvan7 are currently working on a header generation tool from D sources to C++ headers.
It would be great to have std::vector and std::string out of the box in D, but putting it into druntime? Druntime is supposed to be shared among all frontends, isn't it? GCC and Clang probably do not have equivalent vector/string classes that the same D code can be used.
Jan 06 2018
parent Andres Clari <andres steelcode.net> writes:
On Saturday, 6 January 2018 at 13:51:54 UTC, qznc wrote:
 It would be great to have std::vector and std::string out of 
 the box in D, but putting it into druntime? Druntime is 
 supposed to be shared among all frontends, isn't it? GCC and 
 Clang probably do not have equivalent vector/string classes 
 that the same D code can be used.
+1 Supporting std::vector and std::string would be a major help
Jan 06 2018
prev sibling parent Laeeth Isharc <laeeth laeeth.com> writes:
On Saturday, 6 January 2018 at 11:17:56 UTC, Seb wrote:
 On Friday, 5 January 2018 at 13:02:12 UTC, qznc wrote:
 I'm exploring [0] C++ interop after watching Walter's 
 presentation [1].

 [...]
I know about this: https://github.com/Remedy-Entertainment/binderoo https://github.com/dlang/druntime/pull/1802
Binderoo currently is Windows only. I am talking to Ethan about extending it to work on Linux too. Let me know if any other features helpful to add (no promises, but we can see).
Jan 07 2018
prev sibling parent Mengu <mengukagan gmail.com> writes:
On Friday, 5 January 2018 at 13:02:12 UTC, qznc wrote:
 I'm exploring [0] C++ interop after watching Walter's 
 presentation [1].

 I hit a block with classes as template parameters. This means 
 vector<int> works, but vector<Foo> does not. D seems to map 
 vector!Foo to vector<Foo*>. Likewise shared_ptr<Foo> is a 
 problem. Any way to fix that on the D side? The ugly workaround 
 is to adapt the C++ code.

 I understand that this mapping makes sense for function calls 
 because bar(Foo f) in D maps to bar(Foo *f) in C++. And C++ 
 bar(Foo f) has no equivalent in D because classes are reference 
 types.

 On a related note, C++ interop requires to redeclare or even 
 reimplement C++ code. Has anybody started a libcpp-in-d 
 project? I'm looking for basics like vector and string.

 [0] https://github.com/qznc/d-cpptest
 [1] https://youtu.be/IkwaV6k6BmM
is C++ support in LDC better than what we have with DMD? i did checkout your code btw and could not enjoy it more. :)
Jan 06 2018