Skip to content

Instantly share code, notes, and snippets.

@playmer
Last active October 1, 2016 10:01
Show Gist options
  • Save playmer/fe45b30458ecc3ccc816b0b7b98c2e00 to your computer and use it in GitHub Desktop.
Save playmer/fe45b30458ecc3ccc816b0b7b98c2e00 to your computer and use it in GitHub Desktop.
Gives an ICE in MSVC 2015, will probably remove more of this, it's problem is centered on the very ill-formed attempt at writing a correct Binding template to deduce the types of a member function pointer we have some knowledge of.
#include <stdio.h>
class Kiddo
{
};
class CrappyKid : public Kiddo
{
};
class Mum
{
};
class UrMum : public Mum
{
public:
void HelpKiddo(CrappyKid *aKiddo)
{
printf("Helping this kiddo: %p\n", aKiddo);
}
};
template <typename Return, typename Object, typename Event>
struct Binding(Return(Object::*)(Event*))
{
using ReturnType = Return;
using MumType = Object;
using KiddoType = Event;
};
template <typename FunctionType, FunctionType aFunction>
void CallUrFunction(Mum *aMum, Kiddo *aKiddo)
{
(static_cast<Binding<FunctionType>::MumType*>(aMum)->*aFunction)(static_cast<Binding<FunctionType>::KiddoType*>(aKiddo));
}
int Ice()
{
CrappyKid u;
UrMum urMum;
using Invoker = void(*)(Mum*, Kiddo*);
Invoker uSuck = CallUrFunction<decltype(UrMum::HelpKiddo), &UrMum::HelpKiddo>;
uSuck(&urMum, &u);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment