-
Notifications
You must be signed in to change notification settings - Fork 1
/
item4_view_deduce.cpp
61 lines (54 loc) · 1.55 KB
/
item4_view_deduce.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <boost/type_index.hpp>
using namespace std;
#ifndef _MSC_VER
#include <cxxabi.h>
#endif
#include <type_traits>
#include <memory>
#include <string>
#include <cstdlib>
#include <array>
#include <typeinfo>
using namespace std;
template <class T>
std::string
type_name()
{
typedef typename std::remove_reference<T>::type TR;
std::unique_ptr<char, void (*)(void *)> own(
#ifndef _MSC_VER
abi::__cxa_demangle(typeid(TR).name(), nullptr,
nullptr, nullptr),
#else
nullptr,
#endif
std::free);
std::string r = own != nullptr ? own.get() : typeid(TR).name();
if (std::is_const<TR>::value)
r += " const";
if (std::is_volatile<TR>::value)
r += " volatile";
if (std::is_lvalue_reference<T>::value)
r += "&";
else if (std::is_rvalue_reference<T>::value)
r += "&&";
return r;
}
template<typename T>
class TD;
int main(){
using boost::typeindex::type_id_with_cvr;
const int theAnswer = 42;
auto x = theAnswer;
auto a = std::is_same<decltype(theAnswer), decltype(x)>::value;
cout << "theAnswer's type and x's type is : " << a << endl;
cout << "theAnswer's type : " << type_name<decltype(theAnswer)>() << endl;
cout << "x's type : " << type_name<decltype(x)>() << endl;
x = 43;
cout << "After assigning x to 43 " << endl;
cout << "theAnswer is : " << theAnswer << endl;
cout << "x 's type from boost tool : " << type_id_with_cvr<decltype(x)>().pretty_name() << endl;
//TD<decltype(x)> xType;
return 0;
}