On 05/15/2015 09:44 PM, Jonathan M Davis wrote:
On Friday, 15 May 2015 at 18:42:31 UTC, Kagamin wrote:
Many STL types inherit from base classes, yet they are used as value
types: std::string, std::vector etc. Are there plans to support C++
types with inheritance as proper value types in D frontend?

Given that the inheritance they have is actually undesirable when they
are treated as value types, I doubt that there's much need. If you're
using inheritance in C++, you're putting your class on the heap and
accessing it via pointers,> in which case, accessing them in D as classes
makes sense. And if you're using these STL types as value types on the
stack, then they can be treated as value types. Doing otherwise just
risks object slicing, which is not desirable in the least.

So, while I don't know how we're going to be handling STL types (I don't
even know what the current state of C++ state support is, since it keeps
improving), I really don't see why there's value in supported
inheritance with value types. It would just be begging for bugs - which
is why native D types don't support it.

- Jonathan M Davis

He didn't ask about support for object slicing, just support for proper interfacing to value types that happen to use implementation inheritance.


  template<typename _Tp, typename _Alloc = std::allocator<_Tp> >
    class vector : protected _Vector_base<_Tp, _Alloc>
    {


vector is a value type. You won't accidentally slice it, as the parent class is not accessible. _Vector_base is there to make exception safety easier AFAIK. It's basically an implementation detail. (Does anyone know why they are using protected inheritance instead of private inheritance?)

Reply via email to