Skip to content

Instantly share code, notes, and snippets.

@vicyap
Last active November 5, 2016 09:40
Show Gist options
  • Save vicyap/4a242e4b44eb706573c3f965b93c7c70 to your computer and use it in GitHub Desktop.
Save vicyap/4a242e4b44eb706573c3f965b93c7c70 to your computer and use it in GitHub Desktop.
C++17 any demo
#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;
}
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