Any plans to support STL value types?

Dejan Lekic via Digitalmars-d digitalmars-d at puremagic.com
Tue May 19 05:46:49 PDT 2015


On Friday, 15 May 2015 at 19:51:09 UTC, anonymous wrote:
> 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.

How is this a "digital socialism"? :) Nobody forces you anything. 
The community made Phobos - if you do not like it, use something 
else. :) There is Tango/D2 project too, if that one does not fit 
your need, use OR create something else!

Second, what do you mean when you say (type) "D"? D community, D 
programming language, or what? If by D you refer to D as a 
programming language (and that is what I think when you say D) - 
sorry to break it up to you, but EVERY SINGLE language (not just 
programming) forces specific rules upon programmer!

Back to the topic - nobody stops anyone from writing a module 
which provides what the original question was about. Is there any 
value in having STL value types? - I do not see them, but that 
does not mean someone else may see it differently.


More information about the Digitalmars-d mailing list