C++ inline Assembler hack back in 2008

Digging deep in my work from past years I stumbled upon interesting Assembler workaround I made then for C++. I was looking for a solution that could make possible to wrap a class method into Function class object. These days with C++11 it’s just a matter of using std::bind and std::function but I think it’s pretty interesting to see what Assembler could be behind such “simple” task as encapsulating pointer to method.

I’ve found my code on my old pastebin account. There are few things I don’t like in it, so please, don’t comment on it, I don’t like it either :) I’ve just translated comments and code is left as original, gist here.

And here I present the most interesting part, just look at that hacky Assembler:

Here is the usage:

The full code is here on gist.

Time passed

Here on StackOverflow you can see today’s solutions.

I made this around 2008. But Internets. Internets do have almost everything and I have found that there existed a published solution since 2004 which I didn’t know about!

This shows how programming languages, technologies and community evolve which is a nice thing.