On 6/18/2015 1:05 PM, Stefan Ram wrote:
> Victor Bazarov <v.ba...@comcast.invalid> writes:
>> What problem does it solve that cannot be solved any other way?
>
> As I mentioned, programs run faster, when all objects
> of a sequence are in an array instead of irregularly
> spread across a heap.
>
> When one implements polymorphism via pointers, the
> naive solution for a sequence of instances is an
> array of pointers with objects spread in the heap.
> One can get better locality with custom allocators
> that use memory pools, but this is more effort.
>
> When it's possible to store an instance of a subclass
> directly into an object of a class then this would
> enable direct-polymorphism without pointers. This
> would allow one to implement a sequence of objects
> with an array, even when the entries have different
> subclasses. One would not be forced to use the
> indirection via pointers. Objects would not be
> spread across the heap. And it would be natural
> given that »is a« meaning of public inheritance.
What I see you say here is that within the confines of a set of very
strict requirements, we *might* get some advantage in terms of code
execution speed. All that at the price of code maintainability and
readability, not to mention debug-ability... Should probably work OK
when programming a system that, once debugged and deployed, will never
be touched again.
In general, systems that I see developed live longer and mutate rather
actively, being tended to by dozens of programmers at a time.
I don't think that a feature should not be considered if its application
is rare or to solve a niche problem not solved by other means. Take
'goto' for example, there are situations in which it is a convenient, if
not elegant, approach. But introducing more complexity into the
compiler by adding new features to the language, for the sake of
unknown/unproven gains?
> For example, usally every int value can be
> represented by a corresponding double value.
Right, usually. A 64-bit int cannot.
> Insofar, an int »is a« double. An in fact, we /can/
> store int values in double objects.
Not all of them, alas.
> Often, in C++
> one tries to imitate features of primitiv types
> when one builds class types.
Yes, imagined features. Features that don't really give one any
advantages. Distinct types are there for a reason. Don't use 'double'
if you need an 'int'...
> When a class has virtual members, C++ must store
> the type information as a run-time information
> anyway. So when it already has this type information
> at run time, it can use it as well to get the
> type of an instance even without a pointer to it.
I didn't quite get it where the last paragraph fits, sorry. My fault, I
am sure.