fork(1) download
  1. #include <iostream>
  2. #include <map>
  3. #include <set>
  4. using namespace std;
  5.  
  6. struct shape {
  7.  
  8. int x;
  9. };
  10.  
  11.  
  12.  
  13. int main() {
  14. cout.setf(std::ios::boolalpha);
  15. shape arr[6] = {{1},{2},{3},{4},{5},{6}}; // some shapes
  16. map<shape*,set<shape*> > c; // although would consider smart pointers
  17. c[&arr[0]].insert(&arr[1]);
  18. c[&arr[1]].insert(&arr[0]);
  19.  
  20. cout << "Shape 1 collides with 0: " << (bool)c[&arr[1]].count(&arr[0]) <<endl;
  21. cout << "Shape 1 collides with 2: " << (bool)c[&arr[1]].count(&arr[2]) <<endl;
  22. return 0;
  23. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
Shape 1 collides with 0: true
Shape 1 collides with 2: false