#include <memory>
#include <set>
#include <functional>
#include <algorithm>
#include <iostream>
struct Cell {
        int mX;
        Cell(int x) : mX(x) {}
        size_t GetX() const { return mX;}
};
struct CellSorter {
        bool operator()(const std::shared_ptr<Cell>& l, const std::shared_ptr<Cell>& r) const
        {
                return l->GetX() < r->GetX();
        }
};

class CellInCol : public std::unary_function<const std::shared_ptr<Cell>,
                                             bool>
{
public:
    CellInCol( size_t col ) : _col( col ) {}
    bool operator() ( const std::shared_ptr<Cell> &a ) const
    {
        return a->GetX() == _col;
    }
private:
    size_t _col;
};
int main()
{
    typedef std::set<std::shared_ptr<Cell>, CellSorter> Container;
    Container _grid;
    _grid.insert( std::shared_ptr<Cell>(new Cell(1)));
    _grid.insert( std::shared_ptr<Cell>(new Cell(2)));
    _grid.insert( std::shared_ptr<Cell>(new Cell(7)));
    _grid.insert( std::shared_ptr<Cell>(new Cell(10)));
    Container col;
    size_t c = 7;
    std::remove_copy_if( _grid.begin(), _grid.end(),
                         std::inserter( col, col.begin() ),
                         std::not1( CellInCol( c ) ) );
    std::cout << "col has " << col.size() << " elements\n"
              << " the first element is " << (*col.begin())->GetX() << '\n';
}
