C ++. New versions of each method in the template class created with each instance

I have a class template that takes two parameters: one is a type name and the other is a logical one, which determines whether the class will throw an exception if an error occurs.

MyClass.h:

template<typename T, bool signal>
class MyClass {

    // methods which do not use or reference signal
    void Method1(args) {
        // some really long and complex code
    }
    void Method2(args) {
        // some more really long and complex code
    }

    // the method which checks the value of signal
    void throwMethod() {
        if (signal) throw (some exception); // if statement optimized away at compile time
    }
};

main.cpp:

#include "MyClass.h"

void main(int argc, const char * argv[]) {
    MyClass<int, true> instThrow;
    MyClass<int, false> instNoThrow;

    // do something
}

, , , AT ALL. : (Method1, Method2) , ( ) ( ) throwMethod ( ) , , Method1 Method2.

, Apple LLVM compiler 3.0

+3
1

, . , , Method1 Method2. T , .

+3

All Articles