This is the answer of Exercise #9: No for-loops.
Question #10: Widget::DoIt on boost::shared_ptr<Widget>
Replace the for-loop. You will need:
#include <vector> #include <boost/shared_ptr.hpp> struct Widget { void DoIt() const { /* do it */ } }; void DoIt(const std::vector<boost::shared_ptr<Widget> >& v) { const std::size_t sz = v.size(); for (std::size_t i=0; i!=sz; ++i) { v[i]->DoIt(); } }
#include <algorithm> #include <numeric> #include <vector> #include <boost/shared_ptr.hpp> struct Widget { void DoIt() const { /* do it */ } }; void DoIt(const std::vector<boost::shared_ptr<Widget> >& v) { std::for_each(v.begin(),v.end(),boost::mem_fn(&Widget::DoIt)); }