Programming

Friday, November 17, 2006

Today I came up with something really clever - or so I thought. I was trying to determine whether one class was derived from another, but not having much luck. The following solution struck me at 2am last night:

template
class is_derived_from
{
typedef char success;
struct failure { success x[2]; };
static failure f(void*);
static success f(Base*);
public:
static const bool value = sizeof(f((Derived*)0)) == sizeof(success);
};



Unfortunately I googled around a bit and there is one place where this has been invented before, almost verbatim. Darn.

Labels:

0 Comments:

Post a Comment

<< Home