I need a way to check if a templated class's type is void.
Here is my attempt:
template <typename target_type, typename start_function_type, typename end_function_type> class C_rule {
public:
//...
void setIntoEffect(bool true_or_false) {
if (true_or_false == true) {
for (size_t i = 0; i < targets.size(); i++) {
if (typeid(start_function_type) != typeid(void)) {
start_function_type start_function_return_value = enforceOnTarget(targets.at(i));
}
else {
enforceOnTarget(targets.at(i));
}
}
}
else if ((true_or_false == false) && (is_in_effect == true)) {
for (size_t i = 0; i < targets.size(); i++) {
if (typeid(end_function_type) != typeid(void)) {
end_function_type end_function_return_value = removeFromTarget(targets.at(i));
}
else {
removeFromTarget(targets.at(i));
}
}
}
is_in_effect = true_or_false;
}
protected:
//...
private:
//...
};
However, this generates a compiler error complaining about the two variables "start_function_return_value" and "end_function_return_value" being declared void when created an object of C_rule with "start_function_type" and "end_function_type" being void. I'm trying to prevent creating a variable to store the return value from the 'start' and 'end' functions for the rule, if the return type of those functions is void (since void functions obviously do not return anything). And, as you can see, I'm trying to use the typeid operator for that purpose, but it doesn't appear to be working. Apparently, the if statement is still being entered when the start_function_type and end_function_type is void, and I don't know why. Maybe typeid doesn't work with void? I googled the question, but couldn't find an answer, so that's why I'm asking it here.
Thanks in advance.