Can we just have struct inheritence already?

Walter Bright newshound2 at digitalmars.com
Tue Jun 18 09:15:42 UTC 2019


On 6/12/2019 11:29 PM, Manu wrote:
> On Wed, Jun 12, 2019 at 10:25 PM Walter Bright via Digitalmars-d
> <digitalmars-d at puremagic.com> wrote:
>>
>> On 6/11/2019 11:19 AM, Manu wrote:
>>>> Can I ask again, in a different way, why do you need the 0 size?
>>>
>>> To handle base structs with no members.
>>
>> For the 3rd time, why do you need it to have 0 size? I don't know what you mean
>> by "handling" it.
> 
> I hate wasting 8 bytes needlessly. Almost every struct I write is
> carefully packed and aligned to 16, 32, or 64 bytes and allocated in
> pools... that's 50%, 25%, or 12.5% memory wastage.
> There's also ABI compatibility with existing C++ where this is
> super-common. Consider that user-supplied <Allocator> is a base of
> every STL container, that's one case where I've had to deploy the
> static if hack a lot. Those are absolutely not polymorphic types, and
> you couldn't make that mistake no matter how hard you squinted. They
> sometimes use a helper called a 'packed pair' in the STL, which is
> like std::pair (obviously another not-a-polymorphic-type), but where
> one or the other element can be zero-sized and not waste memory.
> It's an aggregation tool.
> 

Have you considered using template mixins? Since you're using a base struct 
merely as a namespace for some functions, that should work.


More information about the Digitalmars-d mailing list