c++ - Finding an element in a shared_ptr container? -
i'm having little problem finding element in vector of shared_ptr
.
here ended with:
std::vector<std::shared_ptr<block>> blocks; bool contains(block* block) { (auto = blocks.begin(); != blocks.end(); ++i) { if ((*i).get() == block) { homecoming true; } } homecoming false; }
however, didn't managed std::find
or std::find_if
. there more c++ compliant way accomplish ?
edit: code have after answer:
bool contains(block* block) { auto found = std::find_if(blocks.begin(), blocks.end(), [block](std::shared_ptr<block> const& i){ homecoming i.get() == block; }); homecoming found != blocks.end(); }
try:
std::find_if(blocks.begin(), blocks.end(), [block](std::shared_ptr<block> const& i){ homecoming i.get() == block; });
c++ pointers containers
No comments:
Post a Comment