fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template<typename T=long>
  5. struct Rect{
  6. T left, top, right, bottom;
  7. Rect( T l, T t, T r, T b ) : left(l), top(t), right(r), bottom(b) { }
  8. bool intersects( const Rect<T>& other ) const{
  9. return other.left <= right && other.right >= left
  10. && other.top <= bottom && other.bottom >= top ;
  11. }
  12. };
  13.  
  14. int main(){
  15. cout << "Intersects: "
  16. << Rect<>( 0, 0, 20, 20 ).intersects( { 10, 10, 100, 100 } );
  17. return 0;
  18. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
Intersects: 1