Advertisement
kalabukdima

useful lambda

Jan 7th, 2018
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. struct Point {
  2.     int x = 0;
  3.     int y = 0;
  4. };
  5.  
  6. const Point operator+(const Point& lhs, const Point& rhs) {
  7.     return {lhs.x + rhs.x, lhs.y + rhs.y}; // C++14
  8. //  return Point{lhs.x + rhs.x, lhs.y + rhs.y}; // C++11
  9. }
  10.  
  11. void bfs(const Matrix<int> a, int N, int M)  {
  12.     const auto inside = [N, M] (const Point& p) {
  13.         return p.x >= 0 && p.y >= 0 && p.x < N && p.y < M;
  14.     };
  15.  
  16.     // ...
  17.     while (!q.empty()) {
  18.         const Point c = q.top();
  19.         // ...
  20.         for (auto dir : dirs) {
  21.             const Point next_c = c + dir;
  22.             if (inside(next_c) && !visited(next_c)) {
  23.                 q.push(next_c);
  24.             }
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement