Here is my program that attempts to use std::conditional to set the type of a member variable based on the value of an integer template parameter.
#include <stdio.h>
#include <type_traits>
using namespace std;
class cool{
public:
cool(){ printf("Cool!\n"); }
};
class notcool{
public:
notcool(){ printf("Not cool!\n"); }
};
template<int N>
class myclass{
public:
typedef std::conditional<N==5,cool,notcool> thetype;
thetype theinst;
};
int main(){
printf("Testing\n");
myclass<5> myc5;
myclass<6> myc6;
printf("Done testing\n");
return 0;
}
I would expect my program to give the following output:
Testing
Cool!
Not cool!
Done testing
Instead, the output is
Testing
Done testing
My compiler is GCC 4.9, and the way I compiled this program was using the command g++ test -std=c++11 -o test
Can anyone tell me why the program does not give the output I expect?