Last active
January 28, 2016 20:05
-
-
Save loliGothicK/4f1320f129a9b9d62673 to your computer and use it in GitHub Desktop.
テンプレートの推論された型をお手軽確認 ref: http://qiita.com/_EnumHack/items/7c8556ab6ddba3a785f8
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
template < typename T > | |
void f(T&&){} | |
void g(int const&){}; | |
int main(){ | |
f(g); | |
} |
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
#include <iostream> | |
#include <typeinfo> | |
using namespace std; | |
template < typename T > | |
void f(T&&){ cout << typeid(T).name() << endl;} | |
void g(int const&){}; | |
int main(){ | |
f(g); | |
} |
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
#include <iostream> | |
#include <typeinfo> | |
#include <cxxabi.h> | |
using namespace std; | |
template < typename T > | |
void f(T&&){ | |
const type_info& id = typeid(T); | |
int stat; | |
char *name = abi::__cxa_demangle(id.name(),0,0,&stat); | |
if( name!=NULL ) { | |
if( stat==0 ) { // ステータスが0なら成功 | |
printf("T = %s",name); | |
} | |
free(name); // freeする必要がある | |
} | |
} | |
void g(int const&){}; | |
int main(){ | |
f(g); | |
} |
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
#include <iostream> | |
#include <boost/type_index.hpp> | |
using namespace std; | |
template < typename T > | |
void f(T&&){ cout << boost::typeindex::type_id_with_cvr<T>().pretty_name() << endl;} | |
void g(int const&){}; | |
int main(){ | |
f(g); | |
} |
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
template < typename T > | |
[[deprecated]] void f(T&&){} | |
void g(int const&){}; | |
int main(){ | |
f(g); | |
} |
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
prog.cc: In function 'int main()': | |
prog.cc:8:8: warning: 'void f(T&&) [with T = void (&)(const int&)]' is deprecated [-Wdeprecated-declarations] | |
f(g); | |
^ | |
>prog.cc:3:21: note: declared here | |
[[deprecated]] void f(T&&){} | |
^ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment