Created
December 23, 2015 14:00
-
-
Save kimyongin/5ad5f007bd68ec84b340 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example program | |
#include <iostream> | |
#include <boost/type_index.hpp> | |
using namespace std; | |
using namespace boost::typeindex; | |
template<typename T> | |
void fn0(const T p) { | |
cout << "T : " << type_id_with_cvr<T>().pretty_name() << endl; | |
cout << "p : " << type_id_with_cvr<decltype(p)>().pretty_name() << endl << endl; | |
} | |
template<typename T> | |
void fn1(const T& p) { | |
cout << "T : " << type_id_with_cvr<T>().pretty_name() << endl; | |
cout << "p : " << type_id_with_cvr<decltype(p)>().pretty_name() << endl << endl; | |
} | |
template<typename T> | |
void fn2(const T&& p) { | |
cout << "T : " << type_id_with_cvr<T>().pretty_name() << endl; | |
cout << "p : " << type_id_with_cvr<decltype(p)>().pretty_name() << endl << endl; | |
} | |
template<typename T> | |
void fn3(T p) { | |
cout << "T : " << type_id_with_cvr<T>().pretty_name() << endl; | |
cout << "p : " << type_id_with_cvr<decltype(p)>().pretty_name() << endl << endl; | |
} | |
template<typename T> | |
void fn4(T& p) { | |
cout << "T : " << type_id_with_cvr<T>().pretty_name() << endl; | |
cout << "p : " << type_id_with_cvr<decltype(p)>().pretty_name() << endl << endl; | |
} | |
template<typename T> | |
void fn5(T&& p) { | |
cout << "T : " << type_id_with_cvr<T>().pretty_name() << endl; | |
cout << "p : " << type_id_with_cvr<decltype(p)>().pretty_name() << endl << endl; | |
} | |
int main() | |
{ | |
const int cx = 10; | |
const int& crx = cx; | |
const int&& crrx = 10; | |
int x = 10; | |
int& rx = x; | |
int&& rrx = 10; | |
cout << "=======================================" << endl; | |
cout << "template<typename T>" << endl; | |
cout << "void fn0(const T p)" << endl; | |
cout << "=======================================" << endl; | |
cout << "const int cx" << endl; | |
fn0(cx); // T:int , p:const int | |
cout << "const int& crx" << endl; | |
fn0(crx); // T:int , p:const int | |
cout << "const int&& crrx" << endl; | |
fn0(crrx); // T:int , p:const int | |
cout << "int x" << endl; | |
fn0(x); // T:int , p:const int | |
cout << "int& rx" << endl; | |
fn0(rx); // T:int , p:const int | |
cout << "int&& rrx" << endl; | |
fn0(rrx); // T:int , p:const int | |
cout << "=======================================" << endl; | |
cout << "template<typename T>" << endl; | |
cout << "void fn1(const T& p)" << endl; | |
cout << "=======================================" << endl; | |
cout << "const int cx" << endl; | |
fn1(cx); // T:int , p:const int & | |
cout << "const int& crx" << endl; | |
fn1(crx); // T:int , p:const int & | |
cout << "const int&& crrx" << endl; | |
fn1(crrx); // T:int , p:const int & | |
cout << "int x" << endl; | |
fn1(x); // T:int , p:const int & | |
cout << "int& rx" << endl; | |
fn1(rx); // T:int , p:const int & | |
cout << "int&& rrx" << endl; | |
fn1(rrx); // T:int , p:const int & | |
//cout << "=======================================" << endl; | |
//cout << "template<typename T>" << endl; | |
//cout << "void fn2(const T&& p)" << endl; | |
//cout << "=======================================" << endl; | |
//cout << "const int cx" << endl; | |
//fn2(cx); | |
//cout << "const int& crx" << endl; | |
//fn2(crx); | |
//cout << "const int&& crrx" << endl; | |
//fn2(crrx); | |
//cout << "int x" << endl; | |
//fn2(x); | |
//cout << "int& rx" << endl; | |
//fn2(rx); | |
//cout << "int&& rrx" << endl; | |
//fn2(rrx); | |
cout << "=======================================" << endl; | |
cout << "template<typename T>" << endl; | |
cout << "void fn3(T p)" << endl; | |
cout << "=======================================" << endl; | |
cout << "const int cx" << endl; | |
fn3(cx); // T:int , p:int | |
cout << "const int& crx" << endl; | |
fn3(crx); // T:int , p:int | |
cout << "const int&& crrx" << endl; | |
fn3(crrx); // T:int , p:int | |
cout << "int x" << endl; | |
fn3(x); // T:int , p:int | |
cout << "int& rx" << endl; | |
fn3(rx); // T:int , p:int | |
cout << "int&& rrx" << endl; | |
fn3(rrx); // T:int , p:int | |
cout << "=======================================" << endl; | |
cout << "template<typename T>" << endl; | |
cout << "void fn4(T& p)" << endl; | |
cout << "=======================================" << endl; | |
cout << "const int cx" << endl; | |
fn4(cx); // T:const int , p:const int & | |
cout << "const int& crx" << endl; | |
fn4(crx); // T:const int , p:const int & | |
cout << "const int&& crrx" << endl; | |
fn4(crrx); // T:const int , p:const int & | |
cout << "int x" << endl; | |
fn4(x); // T:int , p:int & | |
cout << "int& rx" << endl; | |
fn4(rx); // T:int , p:int & | |
cout << "int&& rrx" << endl; | |
fn4(rrx); // T:int , p:int & | |
cout << "=======================================" << endl; | |
cout << "template<typename T>" << endl; | |
cout << "void fn5(T&& p)" << endl; | |
cout << "=======================================" << endl; | |
cout << "const int cx" << endl; | |
fn5(cx); // T:const int & , p:const int & | |
cout << "const int& crx" << endl; | |
fn5(crx); // T:const int & , p:const int & | |
cout << "const int&& crrx" << endl; | |
fn5(crrx); // T:const int & , p:const int & | |
cout << "int x" << endl; | |
fn5(x); // T:int & , p:int & | |
cout << "int& rx" << endl; | |
fn5(rx); // T:int & , p:int & | |
cout << "int&& rrx" << endl; | |
fn5(rrx); // T:int & , p:int & | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment