I just noticed my code repeats this structure a lot:
if( someErrorHappened ){
string errorMsg = "Falcon Punch!";
::GetErrorLoggerInstance()->Log( LOG_TYPE_ERROR, "class", "method", errorMsg );
throw SomeCustomException( errorMsg );
}
I figured I could write a template function so that I could replace all those with a one-liner like this:
LogAndThrowIfError<SomeCustomException>( someErrorHappened, "class", "method", "Falcon Punch!" );
I can do that just fine with my basic templates knowledge. My question is, can I use Boost to ensure that a compile error ensues if the template argument is a class which does not inherit from a specific class? (i.e. I only want to let this function be used for my custom exceptions). Kinda like C#'s where
keyword for generics.
This might seem farfetched, but I need to enforce this because our application has managed and unmanaged code, and our custom native exceptions are mapped to custom managed exceptions, that's why this should only be used with our exceptions.
I'm working in Visual Studio 2010, so I don't have all the fancy C++11 stuff, just some of it (move semantics being the juiciest).