18. コンパイラを使う
18
template <typename T>
class TD; // TD is Type Displayer.
const int x = 0;
auto y = x;
auto z = &x;
TD<decltype(y)> yType;
TD<decltype(z)> zType;
> clang++ -std=c++1y t.cpp
t.cpp:11:21: error: implicit instantiation of undefined
template 'TD<int>‘
...
t.cpp:12:21: error: implicit instantiation of undefined
template 'TD<const int *>‘
...
19. コンパイラを使う –cont.
19
std::map<std::string, std::vector<int>> m;
const auto v = m;
TD<decltype(m)> mType;
> clang++ -std=c++1y t.cpp
...
t.cpp:16:21: error: implicit instantiation of undefined
template
'TD<std::map<std::basic_string<char>, std::vector<int,
std::allocator<int> >,
std::less<std::basic_string<char> >,
std::allocator<std::pair<const std::basic_string<char>,
std::vector<int, std::allocator<int> > > > > >'
TD<decltype(m)> mType;
...
20. typeidを使う
• i: int
• P: pointer
• K: const
20
const int x = 0;
auto y = x;
auto z = &x;
std::cout << typeid(y).name() << std::endl;
std::cout << typeid(z).name() << std::endl;
> clang++ -sd=c++1y t.cpp && ./a.out
i
PKi