On Wed, Feb 03, 2016 at 07:25:55PM +0200, Dicebot via Digitalmars-d-announce 
> On 02/03/2016 07:05 PM, Nick Sabalausky wrote:
> > Something that's been on my mind for a few months, finally got around to
> > a little write-up about it.
> > 
> > We're Overlooking A Key Part of C/C++ to D User Migration:
> > 
> > https://semitwist.com/articles/article/view/we-re-overlooking-a-key-part-of-c-c-d-user-migration
> For plain ABI interop it is actually something that should be doable
> by compiler as part of .di header generation - generate matching
> `extern(C)` wrappers for non-templated code (expanding all arrays to
> ptr + len pairs etc.).
> The problem is how you are going to expose templated stuff which
> dominates most useful D libraries.

This is certainly an interesting idea worth exploring, and certainly
doable for plain ABI interop, as Dicebot says.

For templates... I dunno, some stuff is probably untranslatable, or at
least, can't be translated into a form that's suitable for end-users,
like alias parameters, variadics, tuple/AliasSeq shenanigans, etc.. But
some of the simpler stuff might be doable.

Perhaps... this is a crazy idea that just occurred to me -- write a D to
C++ template syntax translator? So the D library will ship with
autogenerated C++ templates with equivalent functionality.  Simple
templates like containers with a parametrized element type can be easily
translated to the C++ equivalent. The compiler emits the ugly syntax,
but neither library author nor user needs to care, as long as it has
equivalent semantics, and the generated symbols match up (probably
requires extern(C++) wrappers, though, unless you can somehow make the
mangled template symbols match up -- one possibility might be to emit
two symbols that point to the same thing in the object file).

Of course, this is overlooking subtle semantic differences between D
templates and C++ templates, so I'm not sure if this will actually be
workable in practice. And I'm pretty sure some of the things D templates
support aren't translatable to C++ (not to a form a C++ user would find
usable, anyway). Compile-time introspection is probably out of the
question, and CTFE probably needs to hard-boil computed values into the
generated .di files. Not sure what to do if you have static if's inside
a template function, etc..

But still, it's an interesting idea of how to make inroads to the C++
community. Worth considering IMO.


First Rule of History: History doesn't repeat itself -- historians merely 
repeat each other.

Reply via email to