compile-time

CompileTimeChecker from Modern C++ Design not working as expected.

I've recently started reading Modern C++ Design by Andrei Alexandrescu. After reading Compile-Time Assertions, I tried the following code: template<bool> struct CompileTimeChecker { CompileTimeChecker(...){}; }; template<> struct CompileTimeChecker<false>{}; #define STATIC_CHECK(expr, msg) \ {\ class ERROR_##msg{}; \ (void...

How to tell if class contains a certain member function in compile time

say there are 2 classes: struct A{ int GetInt(){ return 10; } }; struct B{ int m; }; I want to use object of type A or B in following function tempate< typename T > int GetInt( const T & t ) { //if it's A, I'll call: return t.GetInt(); //if its' B, I'll call: return t.m; } Now, because there are whole bunch of classes, some c...

boost_assert that a parameter class implements a certain method

Hi, Suppose you have a certain template that takes a parameter class template <typename ConnectorClass> struct myClass { } I want to add a BOOST_ASSERT_MSG to validate that ConnectorClass implements a certain method of signature returnType MethodName(param1, param2) How should i write the assert condition in this case? EDIT: si...

method compile time assertion; still not working

I need a easy way to assert inside a template that a template parameter implements a method (or one of its parent classes). I've read Concept check library but is hard to find an easy example to do simple checks like this one. I've tried to follow other posts (like this one and this other one), which i've modified so i can make it gener...