Re: checking whether two vector references / pointers are the same
Fabian wrote:
For this I would have to be able to check whether the passed output vector
is the same as the input one (see code snippet below) without comparing
the vector contents via their "==" operator.
Note: the ==operator used on vectors (or any other type) only returns if
they are equivalent (i.e. it's always about the value) while the thing you
seem to want it so compare for identity (i.e. whether they are the same
object).
For identity comparisons, there is a simple way in C++, and that is
comparing the addresses.
bool StackOpLRDeconvXY::Execute(const vector<Spimage*>& inPlanes, const
unsigned int planeNum, vector<Spimage*>* outPlanes) const
{
Note: I'm not sure what it means if outPlanes is null. If this is the vector
receiving the data and that vector must be provided, you could use a
reference instead to make that clear.
if (inPlanes != *outPlanes) // This will compare the vector
// elements, right? {
Yes. Here, you could instead use
if( &inPlanes != outPlanes)
to check if the two vectors are the same.
catch(...)
{
PrintError("StackOpLRDeconvXY::Execute()", "error calculating plane");
return false;
}
Not that it matters to your initial problem, but why swallow any exceptions
here? The calling code probably can't continue anyway and is only cluttered
with checks. Just a suggestion though.
cheers
Uli
--
C++ FAQ: http://parashift.com/c++-faq-lite
Sator Laser GmbH
Gesch??ftsf??hrer: Michael W??hrmann, Amtsgericht Hamburg HR B62 932