J
Jacek Dziedzic
Hello!
In my code I have functions like
SendToNode(int dest_node; int i);
SendToNode(int dest_node; double d);
SendToNode(int dest_node; unsigned int u);
and so on, where the function body is the same for all
these overloaded functions, except for one line, which
depends on the type of the second argument to SendToNode,
i.e. this line looks (more or less) like
internal_send_function(dest_node, type_is_int);
internal_send_function(dest_node, type_is_double);
internal_send_function(dest_node, type_is_unsigned_int);
where "type_is_int" etc. are symbolic constants of type int.
The situation is I'm not much of an OOP programmer, still
it looks to me like my SendToNode function is a candidate for
a template. The problem is: how do I do the "branching" in the
template, depending on what the *type* of the argument is?
How do I determine the type of that argument? I tried googling
it up and found something called typeof(), but it looked as if
it was not a part of the standard (perhaps "yet").
Is this where the concept of traits comes into play? What's
the story behind this?
TIA,
- J.
In my code I have functions like
SendToNode(int dest_node; int i);
SendToNode(int dest_node; double d);
SendToNode(int dest_node; unsigned int u);
and so on, where the function body is the same for all
these overloaded functions, except for one line, which
depends on the type of the second argument to SendToNode,
i.e. this line looks (more or less) like
internal_send_function(dest_node, type_is_int);
internal_send_function(dest_node, type_is_double);
internal_send_function(dest_node, type_is_unsigned_int);
where "type_is_int" etc. are symbolic constants of type int.
The situation is I'm not much of an OOP programmer, still
it looks to me like my SendToNode function is a candidate for
a template. The problem is: how do I do the "branching" in the
template, depending on what the *type* of the argument is?
How do I determine the type of that argument? I tried googling
it up and found something called typeof(), but it looked as if
it was not a part of the standard (perhaps "yet").
Is this where the concept of traits comes into play? What's
the story behind this?
TIA,
- J.