Create D binding for C struct containing templated class

Andre Pany andre at s-e-a-p.de
Fri Jun 29 06:04:10 UTC 2018


On Friday, 29 June 2018 at 01:38:23 UTC, evilrat wrote:
> On Thursday, 28 June 2018 at 18:43:11 UTC, Andre Pany wrote:
>> [...]
>
> No, unfortunately D cannot interface with C templates, only C++ 
> templates. But just by coincidence this is C++ source code (and 
> so the templates).
>
>
> So it is possible but there is few catches.
> - template functions/methods could be inlined by compiler, 
> which means you may (or may not) have to implement it in D 
> (either copy-paste and adapt, or make own ABI compatible 
> implementation)
>
> - most of the methods in this particular template is purely C++ 
> specific convenience helpers, all of this isn't strictly needed 
> in D, just for example operator-> could simply be replaced with 
> alias this.
>
> - the only data member in this template is the 
> std::aligned_storage, which you can probably ignore completely 
> and instead just use fixed-size ubyte[] array with align, again 
> just make struct with alias this and align its content same way 
> as aligned_storage does.
>
>
> And much more-more other things to keep in mind.
>
>
> But the most important thing, are you absolutely sure this is a 
> part of the public API and not the implementation specific 
> internals? Because normally you don't #include anything other 
> than .h* files, this is a source file, and it is not even sits 
> in the include folder.

Thanks a lot for the great help.
You are right, until now I haven't looked at the include folder, 
I thought the "surface" folder is the folder with the public api. 
But it seems also in the include folder, the header files 
contains references to the grpc_call struct.
https://github.com/grpc/grpc/blob/master/include/grpc/impl/codegen/grpc_types.h#L70

Kind regards
André


More information about the Digitalmars-d-learn mailing list