Any plans to support STL value types?

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Sat May 16 17:45:08 PDT 2015


On Saturday, 16 May 2015 at 09:11:46 UTC, Kagamin wrote:
> Inheritance in C++ is not always for polymorphism, often it's 
> just functionality inheritance

Exactly, so if D support C++ classes as value types, they'd just 
be declared as structs in D and no inheritance would be required. 
Any functions that existed in a based class could simply be 
declared as being part of the derived class in the D version. 
There is no need for D to know or care that the C++ type is 
implemented via inheritance, because polymorphism isn't 
applicable.

Now, obviously, support would be needed for D to understand C++ 
types well enough to have D structs which correspond with C++ 
classes which are value types, and AFAIK, we don't currently have 
that, but I really don't see why the inheritance factor matters. 
The base class members or functions are simply additional members 
of the derived class as far as D would be concerned, because 
you'd never convert to the base type.

The problem in actually implementing support for it in D is 
likely going to stem from the fact that support for matching the 
C++ memory layout would have to be there as well as matching the 
construction and destruction semantics of C++. And that being the 
case, I expect that it's most likely that support would exist via 
some kind of conversion at the point where C++ and D meet rather 
than truly supporting the C++ value types in D code, but we'll 
just have to wait and see. It's a nasty problem. And we already 
support way better C++ integration than is typically done in 
other languages. Usually, C integration is as far as it goes.

- Jonathan M Davis


More information about the Digitalmars-d mailing list