title: How to filter object in c++
body: <p>Let's say I have a class:</p>
  
  <pre><code>class Cell {
    int ID;
    int valueX;
    int valueY;
  };
  </code></pre>
  
  <p>and in main() I declared vector of Cells:</p>
  
  <pre><code>vector&lt;Cell&gt; myCells;
  </code></pre>
  
  <p>My problem is to write a function that gets vector of Cells, operator (gt - greater than, le - less or equal, and so on), name of a variable and an integer, and returns vector of Cells that meets the requirement?
  For example:</p>
  
  <pre><code>vector&lt;Cells&gt; resultCells = filter(myCells, gt, valueX, 5)
  </code></pre>
  
  <p>is vector of Cells where each cell has valueX greater than 5.</p>
  
  <p>My first attempts required a lot of ifs and switches and I'm sure it's not proper solution.
  Then I asked a friend for a tip, he told me about things like functors, lambdas, std::function, std::map, std::bind, that can help me to do this and I've read about it but I am unable to use in in practise.</p>
  
  <p>One of examples that I've seen on the Internet is <a href="http://www.cprogramming.com/c++11/c++11-lambda-closures.html" rel="nofollow"><em>this</em></a> one, but it's less complex and hard to reuse (for me).</p>