c++ how to assert that all std::shared_ptr in a vector are referring to something
one more way to do it:
assert(std::find(pFoos.begin(), pFoos.end(), nullptr) == pFoos.end());
Another slightly convoluted way to express it with standard functionality only:
assert(std::none_of(pFoos.begin(), pFoos.end(), std::logical_not<std::shared_ptr<Foo>>{}));
From C++14 onwards, you can use the generic specialization of std::logical_not
:
assert(std::none_of(pFoos.begin(), pFoos.end(), std::logical_not<>{}));