Last active
November 5, 2016 09:40
-
-
Save vicyap/4a242e4b44eb706573c3f965b93c7c70 to your computer and use it in GitHub Desktop.
C++17 any demo
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 <experimental/any> | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
using namespace std::experimental; | |
struct A {}; | |
// clang++ -std=c++14 any.cpp -o any | |
int main() { | |
any a; | |
cout << a.type().name() << endl; // v | |
a = 1; | |
cout << a.type().name() << endl; // i | |
a = 1.0; | |
cout << a.type().name() << endl; // d | |
a = "1"; | |
cout << a.type().name() << endl; // Pkc | |
a = string("1"); | |
cout << a.type().name() << endl; // NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE | |
a = A(); | |
cout << a.type().name() << endl; // 1A | |
a = vector<A>(); | |
cout << a.type().name() << endl; // St6vectorI1ASaIS0_EE | |
return 0; | |
} |
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
v | |
i | |
d | |
PKc | |
NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE | |
1A | |
St6vectorI1ASaIS0_EE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment