Skip to content

Instantly share code, notes, and snippets.

@loliGothicK
Last active January 28, 2016 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loliGothicK/4f1320f129a9b9d62673 to your computer and use it in GitHub Desktop.
Save loliGothicK/4f1320f129a9b9d62673 to your computer and use it in GitHub Desktop.
テンプレートの推論された型をお手軽確認 ref: http://qiita.com/_EnumHack/items/7c8556ab6ddba3a785f8
template < typename T >
void f(T&&){}
void g(int const&){};
int main(){
f(g);
}
#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);
}
#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);
}
#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);
}
template < typename T >
[[deprecated]] void f(T&&){}
void g(int const&){};
int main(){
f(g);
}
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