G
Hi All,
I'm just getting started learning to use <algorithm> instead of loads
of little for loops, and I'm looking for a bit of advice/mentoring re:
implementing the following...
I have a vector of boost::shared_ptr's, some of which may be NULL. I'd
like to find out if there are any non-NULL elements in the vector.
Here's what I have at the moment.
typedef std::vector< boost::shared_ptr<::CFiCamera> > tCameraVector;
tCameraVector m_vpCameras;
....
....
bool CIIDCCaptureFacade::IsHardwareAvailable() const
{
//check for at least one initialized (non-NULL) camera
tCameraVector::const_iterator itCam = std::find_if(
m_vpCameras.begin(), m_vpCameras.end(),
std::bind2nd( std::not_equal_to<tCameraVector::value_type>(),
tCameraVector::value_type() )
);
return itCam != m_vpCameras.end();
}
Firstly, will this implementation meet the spec? I think it will.
Secondly, does anyone have any feedback on whether this is the 'right'
way to implement this using stl? Of course that's subjective, but I'm
looking for a little reassurance that I'm not getting into bad habits
right off the bat.
Cheers and TIA,
Pete
I'm just getting started learning to use <algorithm> instead of loads
of little for loops, and I'm looking for a bit of advice/mentoring re:
implementing the following...
I have a vector of boost::shared_ptr's, some of which may be NULL. I'd
like to find out if there are any non-NULL elements in the vector.
Here's what I have at the moment.
typedef std::vector< boost::shared_ptr<::CFiCamera> > tCameraVector;
tCameraVector m_vpCameras;
....
....
bool CIIDCCaptureFacade::IsHardwareAvailable() const
{
//check for at least one initialized (non-NULL) camera
tCameraVector::const_iterator itCam = std::find_if(
m_vpCameras.begin(), m_vpCameras.end(),
std::bind2nd( std::not_equal_to<tCameraVector::value_type>(),
tCameraVector::value_type() )
);
return itCam != m_vpCameras.end();
}
Firstly, will this implementation meet the spec? I think it will.
Secondly, does anyone have any feedback on whether this is the 'right'
way to implement this using stl? Of course that's subjective, but I'm
looking for a little reassurance that I'm not getting into bad habits
right off the bat.
Cheers and TIA,
Pete