Blog: July 2012

Use SFINAE to unit test inheritance

| Matthias | Comments 1

Just recently I came across a nice appliance of the C++ SFINAE pattern, when I was trying to write some unit tests (using googletest) for a C++ template metaprogramming class that creates a type hierarchy of a given typelist.

Here is a simplified version of what I wanted to test:

#include "gtest/gtest.h" 
class A {};
class B {};
class C {};

typedef TypeList BaseClasses;

class Foo : public InheritFrom 

TEST(InheritFrom, TestCorrectInheritance)
  Foo f; A* a = &f; //this will work 
  C* c = &f; //this will cause a compile time error

Read on

We moved in

| Gerd

Since 1st of July E.S.R.Labs resides in the Friendsfactory (Munich East). As you can see the Friendsfactory provides a nice startup atmosphere ;).

Read on