Boost logo

Boost :

Subject: Re: [boost] [property] interest in C# like properties for C++?
From: Peder Holt (peder.holt_at_[hidden])
Date: 2009-10-20 16:19:36


2009/10/20 Agustín K-ballo Bergé <kaballo86_at_[hidden]>

> Sid Sacek escribió:
> > Sorry, but your design is flawed.
> >
> > This code should compile according to your design and the C# rules, but
> it doesn't. For it to actually be C# compliant, a property must take up no
> space at all, but yours does, unfortunately. Since you're embedding an
> object inside another object, I don't see how you can use this design to
> achieve that goal. No disrespect.
>
This is indeed true, but it will always be the case for a member object.
> Since the technique already relies on undefined behaviour
> (derreferencing a null pointer or calling offsetof on a non-POD type),
> it may do so again and pack all properties inside a union. This will fix
> the space overhead to the minimum, regardless of the number of
> properties. Check Boost.Proto internals for the definition of
> virtual_member, it applies such trick.
>

Thank you! I'll look into that. I hadn't thought of using unions to get the
size down. I'll look into this.

>
> I don't think I'll choose syntactic sugar if the cost is relying on
> undefined behaviour.
>
> I actually tend to agree with you, but I thought the idea was kind of neat,
so I thought I should post it.
Using properties like this will be syntactic sugar, but the implementation
is black box.
It would be interesting to see for what cases and compilers this will fail.
I have tested it for different scenarios (virtual base classes, multiple
base classes, classes with rtti etc) for VC8 and GCC (online compiler) and
they do the right thing.

> Agustín K-ballo Bergé.-
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk