fork download
  1. #include <iostream>
  2. #include <array>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. void func3()
  7. {
  8. for (auto & v : ([]() -> std::vector<int>& { static std::vector<int> vec {1, 2, 3, 4}; return vec; })())
  9. cout << ' ' << v;
  10. }
  11.  
  12. void func4()
  13. {
  14. for (auto & v : ([](){ static std::array<int, 4> arr {1, 2, 3, 4}; return arr; })())
  15. cout << ' ' << v;
  16. }
  17.  
  18. int main() {
  19. func3();
  20. func4();
  21. return 0;
  22. }
Success #stdin #stdout 0s 4540KB
stdin
Standard input is empty
stdout
 1 2 3 4 1 2 3 4