I'm learning how to use type_traits
with C++11 and I'm told that type_traits
works at compile time.
I'm really surprised. I've made a test as below:
class A {virtual void foo();};
class B : public A {};
constexpr bool b = std::is_base_of<A, B>::value;
constexpr bool bb = std::is_polymorphic<A>::value;
constexpr bool bb2 = std::is_polymorphic<B>::value;
int main()
{
return 0;
}
I compile this piece of code with the command: g++ -std=c++11 main.cpp -g
and get a binary file a.out
.
Then I execute the command objdump -dj .rodata a.out
and get the output:
./a.out: file format elf64-x86-64
Disassembly of section .rodata:
0000000000000830 <_IO_stdin_used>:
830: 01 00 02 00 ....
0000000000000834 <_ZStL19piecewise_construct>:
...
0000000000000835 <_ZL1b>:
835: 01 .
0000000000000836 <_ZL2bb>:
836: 01 .
0000000000000837 <_ZL3bb2>:
837: 01 .
OK, type_traits
does work at compile time.
But how? Or does it mean that the c++ compiler could get all of polymorphism information at compile time? I always thought that polymorphism information was all about runtime stuff...
Aucun commentaire:
Enregistrer un commentaire