fork download
  1. #include <iostream>
  2. #include <variant>
  3. #include <vector>
  4. #include <string>
  5.  
  6. void dump(std::vector<std::variant<int, std::string>>v) {
  7. for (auto &e : v) {
  8. if (std::holds_alternative<int>(e)) {
  9. int &x = std::get<int>(e);
  10. std::cout << " " << x << std::endl;
  11. } else if (std::holds_alternative<std::string>(e)) {
  12. std::string &x = std::get<std::string>(e);
  13. std::cout << " " << x << std::endl;
  14. }
  15. }
  16. }
  17.  
  18. void f(std::vector<std::variant<int, std::string>> v1, std::vector<std::variant<int, std::string>> v2) {
  19. std::cout << "v1:" << std::endl;
  20. dump(v1);
  21. std::cout << "v2:" << std::endl;
  22. dump(v2);
  23. }
  24.  
  25. int main() {
  26. std::vector<std::variant<int, std::string>> v1, v2;
  27. v1.emplace_back(3);
  28. v1.emplace_back(std::string("abc"));
  29. v1.emplace_back(55);
  30. v1.emplace_back(std::string("xyz"));
  31.  
  32. v2.emplace_back("abcde");
  33. v2.emplace_back(324);
  34. v2.emplace_back(551);
  35. v2.emplace_back(std::string("rstuvw"));
  36.  
  37. f(v1, v2);
  38.  
  39. return 0;
  40. }
  41. /* end */
  42.  
  43.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:6:28: error: ‘variant’ is not a member of ‘std’
 void dump(std::vector<std::variant<int, std::string>>v) {
                            ^~~~~~~
prog.cpp:6:28: note: ‘std::variant’ is only available from C++17 onwards
prog.cpp:6:28: error: ‘variant’ is not a member of ‘std’
prog.cpp:6:28: note: ‘std::variant’ is only available from C++17 onwards
prog.cpp:6:52: error: template argument 1 is invalid
 void dump(std::vector<std::variant<int, std::string>>v) {
                                                    ^~
prog.cpp:6:52: error: template argument 2 is invalid
prog.cpp:6:28: error: ‘variant’ is not a member of ‘std’
 void dump(std::vector<std::variant<int, std::string>>v) {
                            ^~~~~~~
prog.cpp:6:28: note: ‘std::variant’ is only available from C++17 onwards
prog.cpp:6:28: error: ‘variant’ is not a member of ‘std’
prog.cpp:6:28: note: ‘std::variant’ is only available from C++17 onwards
prog.cpp:6:52: error: template argument 1 is invalid
 void dump(std::vector<std::variant<int, std::string>>v) {
                                                    ^~
prog.cpp:6:52: error: template argument 2 is invalid
prog.cpp:6:28: error: ‘variant’ is not a member of ‘std’
 void dump(std::vector<std::variant<int, std::string>>v) {
                            ^~~~~~~
prog.cpp:6:28: note: ‘std::variant’ is only available from C++17 onwards
prog.cpp:6:28: error: ‘variant’ is not a member of ‘std’
prog.cpp:6:28: note: ‘std::variant’ is only available from C++17 onwards
prog.cpp:6:52: error: template argument 1 is invalid
 void dump(std::vector<std::variant<int, std::string>>v) {
                                                    ^~
prog.cpp:6:52: error: template argument 2 is invalid
prog.cpp:6:16: error: variable or field ‘dump’ declared void
 void dump(std::vector<std::variant<int, std::string>>v) {
                ^~~~~~
prog.cpp:6:28: error: ‘variant’ is not a member of ‘std’
 void dump(std::vector<std::variant<int, std::string>>v) {
                            ^~~~~~~
prog.cpp:6:28: note: ‘std::variant’ is only available from C++17 onwards
prog.cpp:6:28: error: ‘variant’ is not a member of ‘std’
prog.cpp:6:28: note: ‘std::variant’ is only available from C++17 onwards
prog.cpp:6:52: error: template argument 1 is invalid
 void dump(std::vector<std::variant<int, std::string>>v) {
                                                    ^~
prog.cpp:6:52: error: template argument 2 is invalid
prog.cpp:18:25: error: ‘variant’ is not a member of ‘std’
 void f(std::vector<std::variant<int, std::string>> v1, std::vector<std::variant<int, std::string>> v2) {
                         ^~~~~~~
prog.cpp:18:25: note: ‘std::variant’ is only available from C++17 onwards
prog.cpp:18:25: error: ‘variant’ is not a member of ‘std’
prog.cpp:18:25: note: ‘std::variant’ is only available from C++17 onwards
prog.cpp:18:49: error: template argument 1 is invalid
 void f(std::vector<std::variant<int, std::string>> v1, std::vector<std::variant<int, std::string>> v2) {
                                                 ^~
prog.cpp:18:49: error: template argument 2 is invalid
prog.cpp:18:25: error: ‘variant’ is not a member of ‘std’
 void f(std::vector<std::variant<int, std::string>> v1, std::vector<std::variant<int, std::string>> v2) {
                         ^~~~~~~
prog.cpp:18:25: note: ‘std::variant’ is only available from C++17 onwards
prog.cpp:18:25: error: ‘variant’ is not a member of ‘std’
prog.cpp:18:25: note: ‘std::variant’ is only available from C++17 onwards
prog.cpp:18:49: error: template argument 1 is invalid
 void f(std::vector<std::variant<int, std::string>> v1, std::vector<std::variant<int, std::string>> v2) {
                                                 ^~
prog.cpp:18:49: error: template argument 2 is invalid
prog.cpp:18:25: error: ‘variant’ is not a member of ‘std’
 void f(std::vector<std::variant<int, std::string>> v1, std::vector<std::variant<int, std::string>> v2) {
                         ^~~~~~~
prog.cpp:18:25: note: ‘std::variant’ is only available from C++17 onwards
prog.cpp:18:25: error: ‘variant’ is not a member of ‘std’
prog.cpp:18:25: note: ‘std::variant’ is only available from C++17 onwards
prog.cpp:18:49: error: template argument 1 is invalid
 void f(std::vector<std::variant<int, std::string>> v1, std::vector<std::variant<int, std::string>> v2) {
                                                 ^~
prog.cpp:18:49: error: template argument 2 is invalid
prog.cpp:18:13: error: variable or field ‘f’ declared void
 void f(std::vector<std::variant<int, std::string>> v1, std::vector<std::variant<int, std::string>> v2) {
             ^~~~~~
prog.cpp:18:25: error: ‘variant’ is not a member of ‘std’
 void f(std::vector<std::variant<int, std::string>> v1, std::vector<std::variant<int, std::string>> v2) {
                         ^~~~~~~
prog.cpp:18:25: note: ‘std::variant’ is only available from C++17 onwards
prog.cpp:18:25: error: ‘variant’ is not a member of ‘std’
prog.cpp:18:25: note: ‘std::variant’ is only available from C++17 onwards
prog.cpp:18:49: error: template argument 1 is invalid
 void f(std::vector<std::variant<int, std::string>> v1, std::vector<std::variant<int, std::string>> v2) {
                                                 ^~
prog.cpp:18:49: error: template argument 2 is invalid
prog.cpp:18:73: error: ‘variant’ is not a member of ‘std’
 void f(std::vector<std::variant<int, std::string>> v1, std::vector<std::variant<int, std::string>> v2) {
                                                                         ^~~~~~~
prog.cpp:18:73: note: ‘std::variant’ is only available from C++17 onwards
prog.cpp:18:73: error: ‘variant’ is not a member of ‘std’
prog.cpp:18:73: note: ‘std::variant’ is only available from C++17 onwards
prog.cpp:18:97: error: template argument 1 is invalid
 void f(std::vector<std::variant<int, std::string>> v1, std::vector<std::variant<int, std::string>> v2) {
                                                                                                 ^~
prog.cpp:18:97: error: template argument 2 is invalid
prog.cpp: In function ‘int main()’:
prog.cpp:26:20: error: ‘variant’ is not a member of ‘std’
   std::vector<std::variant<int, std::string>> v1, v2;
                    ^~~~~~~
prog.cpp:26:20: note: ‘std::variant’ is only available from C++17 onwards
prog.cpp:26:20: error: ‘variant’ is not a member of ‘std’
prog.cpp:26:20: note: ‘std::variant’ is only available from C++17 onwards
prog.cpp:26:44: error: template argument 1 is invalid
   std::vector<std::variant<int, std::string>> v1, v2;
                                            ^~
prog.cpp:26:44: error: template argument 2 is invalid
prog.cpp:27:6: error: request for member ‘emplace_back’ in ‘v1’, which is of non-class type ‘int’
   v1.emplace_back(3);
      ^~~~~~~~~~~~
prog.cpp:28:6: error: request for member ‘emplace_back’ in ‘v1’, which is of non-class type ‘int’
   v1.emplace_back(std::string("abc"));
      ^~~~~~~~~~~~
prog.cpp:29:6: error: request for member ‘emplace_back’ in ‘v1’, which is of non-class type ‘int’
   v1.emplace_back(55);
      ^~~~~~~~~~~~
prog.cpp:30:6: error: request for member ‘emplace_back’ in ‘v1’, which is of non-class type ‘int’
   v1.emplace_back(std::string("xyz"));
      ^~~~~~~~~~~~
prog.cpp:32:6: error: request for member ‘emplace_back’ in ‘v2’, which is of non-class type ‘int’
   v2.emplace_back("abcde");
      ^~~~~~~~~~~~
prog.cpp:33:6: error: request for member ‘emplace_back’ in ‘v2’, which is of non-class type ‘int’
   v2.emplace_back(324);
      ^~~~~~~~~~~~
prog.cpp:34:6: error: request for member ‘emplace_back’ in ‘v2’, which is of non-class type ‘int’
   v2.emplace_back(551);
      ^~~~~~~~~~~~
prog.cpp:35:6: error: request for member ‘emplace_back’ in ‘v2’, which is of non-class type ‘int’
   v2.emplace_back(std::string("rstuvw"));
      ^~~~~~~~~~~~
prog.cpp:37:3: error: ‘f’ was not declared in this scope
   f(v1, v2);
   ^
stdout
Standard output is empty