litb's Blog

Friday, December 30, 2011

In one of my previous posts I showed some code that accesses a private member, that now has been posted on the boost mailing list as a possible utility for boost serialization to access private attributes (OH MY, I had no idea such a thing actually could have uses!).

I realized that it would be beneficial to have an alternative implementation because the previous code suffered from the Static Initialization Order Fiasco. The following code does not suffer from that problem anymore:

Note that the explicit declaration of "get" inside of "A_f" is important, because we want "get" to be visible to ADL, and the rob template specialization is not an associated class of "A_f" (we could have declared it globally too, if we wanted, but then it would be visible for anyone). To overcome that, we could introduce some utility class we derive from:

Can't put a block around several cases, so sswitch is incompatible to
Duffs device.

The to-be-switched value is always copied - there is no automatic deduction for lvalues
such that they would use references and that only rvalues would be copied

On the goodness sides, sswitch can use native break keywords with the expected semantics, works with any type (not just strings) and also supports fall-through like the built-in switch.
Here is how it can be used.

Notice that since we insert extra braces between each case label (to prevent the code in between to be executed if we haven't hit a label yet), we can't use a plain "default:" at the end, as would be desired by me.
We can jump inside if we want

Saturday, July 3, 2010

So, always thought that it's impossible without undefined behavior to access private members of arbitrary classes without being friend.

Today I noticed I've been horribly wrong, after reading some insightful commit to the clang compiler, that enabled it to allow explicit instantiation to disregard accessibilities, as per the Standard. This enables us to access private members of others. As an experiment, I created some class templates

Saturday, November 1, 2008

So now I've read many blogs out there. And I think it's time that I also own some blogs about what I'm doing with my spare time and whatnot :P So I came across blogger.com and thought it would be a good idea to get my hands dirty and create one. So here we are.

First of all I want to tell you that pacman.d mirrorlist is sometimes really not ordered all that well :P So after waiting another round of minute for the VLC package to download completely, I figured it would be the best to just sit down and write this script:

What does it do? Well, it basicially finds out the currently best order for the mirrorlist file, so that the fastest mirror is at the top. After running it, I was really impressed about the speed of pacman. It rushed through like a tiger :P