Advertisement
999ms

Untitled

Oct 14th, 2021
1,187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define all(x) begin(x),end(x)
  3. using namespace std;
  4.  
  5. struct Data {
  6.     // pjri gnva
  7.     const std::type_info &typeInfo;
  8.     char *bytes = nullptr;
  9.  
  10.     template<typename T>
  11.     explicit Data(T &x)
  12.             : typeInfo(typeid(x)) {
  13.         bytes = new char[sizeof(x)];
  14.         memcpy(bytes, reinterpret_cast<char *>(&x), sizeof(x));
  15.     }
  16.  
  17.     template<typename T>
  18.     T *get() {
  19.         if (typeInfo.hash_code() == typeid(T).hash_code()) {
  20.             return reinterpret_cast<T *>(bytes);
  21.         }
  22.         return (T *) nullptr;
  23.     }
  24. };
  25.  
  26. struct MyType {
  27. } myTypeElement;
  28.  
  29. void solve() {
  30.     vector<Data> elements;
  31.     int n = 50;
  32.     string a = "rwqerqwe";
  33.     set<int> kek;
  34.     vector<double> vec;
  35.     vector<Data> data;
  36.     data.emplace_back(n);
  37.     data.emplace_back(a);
  38.     data.emplace_back(kek);
  39.     data.emplace_back(vec);
  40.     data.emplace_back(myTypeElement);
  41. }
  42.  
  43.  
  44. int main() {
  45.     ios_base::sync_with_stdio(false);
  46.     cin.tie(nullptr);
  47.     cout.tie(nullptr);
  48.     solve();
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement