// http://stackoverflow.com/questions/14917169/finding-an-element-in-a-shared-ptr-container/14917562#14917562

#include <vector>
#include <memory>
#include <algorithm>
#include <iostream>
 
using namespace std;
 
struct Block
{
    bool in_container(const vector<shared_ptr<Block>>& blocks)
    {
        auto end = blocks.end();
        return end != find_if(blocks.begin(), end,
                              [this](shared_ptr<Block> const& i)
                                  { return i.get() == this; });
    }
};
 
int main()
{
    auto block1 = make_shared<Block>();
    auto block2 = make_shared<Block>();
   
    vector<shared_ptr<Block>> blocks;
    blocks.push_back(block1);
    
    block1->in_container(blocks) ?
        cout << "block1 is in the container\n" :
        cout << "block1 is not in the container\n";
        
    block2->in_container(blocks) ?
        cout << "block2 is in the container\n" :
        cout << "block2 is not in the container\n";
    
    return 0;
}