On Friday, 15 May 2015 at 19:44:29 UTC, 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
rust does it just fine without slicing, and supports both static
dispatch and dynamic dispatch through the same interface.
http://blog.rust-lang.org/2015/05/11/traits.html
honestly, this is one of the worst parts of D. Being forced to
code a certain way because it might be misused is the equivalent
of digital socialism.