fork download
  1. #include <vector>
  2. #include <array>
  3.  
  4. struct A
  5. {
  6. const unsigned int id;
  7.  
  8. std::vector<const A*> predecessors;
  9.  
  10. A(unsigned int id) : id(id) {}
  11. void setPredecessors(std::vector<const A*> predecessors) { this->predecessors = predecessors; }
  12. };
  13.  
  14. const std::array<A, 4>& get_registers() {
  15. static std::array<A, 4> v =
  16. {
  17. A(0),
  18. A(1),
  19. A(2),
  20. A(3),
  21. };
  22. if (v[0].predecessors.size()==0) { //initialize it
  23. v[0].setPredecessors({&v[1],&v[2]});
  24. //etc
  25. }
  26. return v;
  27. }
  28.  
  29. const std::array<A, 4>& v = get_registers();
  30. const A &a0 = v[0];
  31. const A &a1 = v[1];
  32. const A &a2 = v[2];
  33. const A &a3 = v[3];
  34.  
  35. int main()
  36. {
  37. return 0;
  38. }
Success #stdin #stdout 0s 3012KB
stdin
Standard input is empty
stdout
Standard output is empty