D
David Portabella
Hello,
I have the following template class:
++++++++++++++++++++++
template <class Value> class Test {
public:
void f() {
if (typeid(Value) == typeid(string))
cout << "Value is a string" << endl;
else
cout << "Value is not a string" << endl;
}
};
+++++++++++++++++++++
Then, given the following code:
+++++++++++++++++++++
Test<string> test1;
test1.f();
+++++++++++++++++++++
is "typeid(Value) == typeid(string)" resolved at compilation time or
at execution time?
(that is, in the same way that "3==3" is resolved at compilation time,
because of gcc optimizes the code)
-------
And in general,
how to check if the compiler optimized such things?
that is, with g++ -S I get the assembler code, but it is difficult to
see something there. is there an intermediate language between cpp and
the -S output?
maybe something that converts c++ to c? that would be useful to see
what the compiler achieve to optimize.
Many thanks,
DAvid
I have the following template class:
++++++++++++++++++++++
template <class Value> class Test {
public:
void f() {
if (typeid(Value) == typeid(string))
cout << "Value is a string" << endl;
else
cout << "Value is not a string" << endl;
}
};
+++++++++++++++++++++
Then, given the following code:
+++++++++++++++++++++
Test<string> test1;
test1.f();
+++++++++++++++++++++
is "typeid(Value) == typeid(string)" resolved at compilation time or
at execution time?
(that is, in the same way that "3==3" is resolved at compilation time,
because of gcc optimizes the code)
-------
And in general,
how to check if the compiler optimized such things?
that is, with g++ -S I get the assembler code, but it is difficult to
see something there. is there an intermediate language between cpp and
the -S output?
maybe something that converts c++ to c? that would be useful to see
what the compiler achieve to optimize.
Many thanks,
DAvid