Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <type_traits>
  2. #include <variant>
  3. #include <vector>
  4. #include <iostream>
  5. #include <string>
  6.  
  7.  
  8. using Var1 = std::variant<uint32_t, float, char>;
  9. using Var2 = std::variant<char, double>;
  10.  
  11. template< class ... TArgs> void func(TArgs && ... args) {
  12.        
  13.         auto pr = [](auto && item) {
  14.                
  15.                 std::cout << "type: " << typeid(item).name() << std::endl;
  16.                 std::visit([](auto && arg) {
  17.                                 std::cout << "item value: '" << arg << "', type: " << typeid(arg).name() << std::endl;
  18.                
  19.                 },
  20.                 item );
  21.         };
  22.  
  23.        
  24.         (pr(args) , ...);
  25. };
  26.  
  27.  
  28. int main () {
  29.  
  30.         Var1 oObj1(0.1f);
  31.         Var2 oObj2('c');
  32.  
  33.         func(oObj1, oObj2);
  34.  
  35.         return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement