How do I accomplish the following in C++, and what is doing such things called?
template <bool S>
class NuclearPowerplantControllerFactoryProviderFactory {
// if S == true
typedef int data_t;
// if S == false
typedef unsigned int data_t;
};
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
By specialization:
You can choose to make one of the two cases the primary template and the other one the specialization, but I prefer this more symmetric version, given that
boolcan only have two values.If this is the first time you see this, you might also like to think about partial specialization:
As @Nawaz says, the easiest way is probably to
#include <type_traits>and say: