I have a simple function template:
#include <iostream>
using namespace std;
template <class T>
T GetMax (T a, T b) {
T result;
result = (a > b) ? a : b;
return (result);
}
int main () {
cout << GetMax<int>(5, 6) << endl;
cout << GetMax<long>(10, 5) << endl;
return 0;
}
The above example will generate 2 function template instantiations, one for int and another for long. Is there any g++ option to view the function template instantiations?
You can use the
nmprogram (part of binutils) to see the list of symbols used by your program. For example:I don’t know why each one has two copies, one with a
.ehsuffix, but otherwise you can tell that this particular function was instantiated twice. If you version ofnmsupports the-C/--demangleflag, you can use that to get readable names:If that option isn’t supported, you can use
c++filtto demangle them:So, you can see that
GetMaxwas instantiated withintandlongrespectively.