simplify Functor::operator== implementation. Thanks to Eric Beyeler
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@676 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
9233d249c9
commit
ee00d7fb60
1 changed files with 16 additions and 63 deletions
|
@ -38,7 +38,6 @@
|
|||
//#define LOKI_FUNCTORS_ARE_COMPARABLE
|
||||
#endif
|
||||
|
||||
//#define LOKI_FUNCTOR_DEBUG
|
||||
|
||||
/// \namespace Loki
|
||||
/// All classes of Loki are in the Loki namespace
|
||||
|
@ -92,11 +91,7 @@ namespace Loki
|
|||
static U* Clone(U* pObj)
|
||||
{
|
||||
if (!pObj) return 0;
|
||||
#ifdef LOKI_FUNCTOR_DEBUG
|
||||
U* pClone = dynamic_cast<U*>(pObj->DoClone());
|
||||
#else
|
||||
U* pClone = static_cast<U*>(pObj->DoClone());
|
||||
#endif
|
||||
assert(typeid(*pClone) == typeid(*pObj));
|
||||
return pClone;
|
||||
}
|
||||
|
@ -105,10 +100,7 @@ namespace Loki
|
|||
#ifdef LOKI_FUNCTORS_ARE_COMPARABLE
|
||||
|
||||
virtual bool operator==(const FunctorImplBase&) const = 0;
|
||||
|
||||
// there is no static information if Functor holds a member function
|
||||
// or a free function; this is the main difference to tr1::function
|
||||
virtual bool isMemberFuncPtr() const = 0;
|
||||
|
||||
#endif
|
||||
|
||||
};
|
||||
|
@ -961,20 +953,15 @@ namespace Loki
|
|||
|
||||
#ifdef LOKI_FUNCTORS_ARE_COMPARABLE
|
||||
|
||||
bool isMemberFuncPtr() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const typename Base::FunctorImplBaseType& rhs) const
|
||||
{
|
||||
if( rhs.isMemberFuncPtr() )
|
||||
return false; // cannot be equal
|
||||
#ifdef LOKI_FUNCTOR_DEBUG
|
||||
const FunctorHandler& fh = dynamic_cast<const FunctorHandler&>(rhs);
|
||||
#else
|
||||
// there is no static information if Functor holds a member function
|
||||
// or a free function; this is the main difference to tr1::function
|
||||
if(typeid(*this) != typeid(rhs))
|
||||
return false; // cannot be equal
|
||||
|
||||
const FunctorHandler& fh = static_cast<const FunctorHandler&>(rhs);
|
||||
#endif
|
||||
// if this line gives a compiler error, you are using a function object.
|
||||
// you need to implement bool MyFnObj::operator == (const MyFnObj&) const;
|
||||
return f_==fh.f_;
|
||||
|
@ -1092,21 +1079,12 @@ namespace Loki
|
|||
|
||||
#ifdef LOKI_FUNCTORS_ARE_COMPARABLE
|
||||
|
||||
bool isMemberFuncPtr() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator==(const typename Base::FunctorImplBaseType& rhs) const
|
||||
{
|
||||
if(!rhs.isMemberFuncPtr())
|
||||
return false;
|
||||
|
||||
#ifdef LOKI_FUNCTOR_DEBUG
|
||||
const MemFunHandler& mfh = dynamic_cast<const MemFunHandler&>(rhs);
|
||||
#else
|
||||
if(typeid(*this) != typeid(rhs))
|
||||
return false; // cannot be equal
|
||||
|
||||
const MemFunHandler& mfh = static_cast<const MemFunHandler&>(rhs);
|
||||
#endif
|
||||
// if this line gives a compiler error, you are using a function object.
|
||||
// you need to implement bool MyFnObj::operator == (const MyFnObj&) const;
|
||||
return pObj_==mfh.pObj_ && pMemFn_==mfh.pMemFn_;
|
||||
|
@ -1316,14 +1294,6 @@ namespace Loki
|
|||
|
||||
#ifdef LOKI_FUNCTORS_ARE_COMPARABLE
|
||||
|
||||
bool isMemberFuncPtr() const
|
||||
{
|
||||
if(spImpl_.get()!=0)
|
||||
return spImpl_.get()->isMemberFuncPtr();
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const Functor& rhs) const
|
||||
{
|
||||
if(spImpl_.get()==0 && rhs.spImpl_.get()==0)
|
||||
|
@ -1556,24 +1526,14 @@ namespace Loki
|
|||
|
||||
#ifdef LOKI_FUNCTORS_ARE_COMPARABLE
|
||||
|
||||
bool isMemberFuncPtr() const
|
||||
{
|
||||
return f_.isMemberFuncPtr();
|
||||
}
|
||||
|
||||
bool operator==(const typename Base::FunctorImplBaseType& rhs) const
|
||||
{
|
||||
isMemberFuncPtr();
|
||||
if(typeid(*this) != typeid(rhs))
|
||||
return false; // cannot be equal
|
||||
// if this line gives a compiler error, you are using a function object.
|
||||
// you need to implement bool MyFnObj::operator == (const MyFnObj&) const;
|
||||
#ifdef LOKI_FUNCTOR_DEBUG
|
||||
return f_ == ((dynamic_cast<const BinderFirst&> (rhs)).f_) &&
|
||||
b_ == ((dynamic_cast<const BinderFirst&> (rhs)).b_);
|
||||
|
||||
#else
|
||||
return f_ == ((static_cast<const BinderFirst&> (rhs)).f_) &&
|
||||
b_ == ((static_cast<const BinderFirst&> (rhs)).b_);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1698,24 +1658,14 @@ namespace Loki
|
|||
|
||||
#ifdef LOKI_FUNCTORS_ARE_COMPARABLE
|
||||
|
||||
bool isMemberFuncPtr() const
|
||||
{
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const typename Base::Impl::FunctorImplBaseType& rhs) const
|
||||
{
|
||||
if(typeid(*this) != typeid(rhs))
|
||||
return false; // cannot be equal
|
||||
// if this line gives a compiler error, you are using a function object.
|
||||
// you need to implement bool MyFnObj::operator == (const MyFnObj&) const;
|
||||
#ifdef LOKI_FUNCTOR_DEBUG
|
||||
return f1_ == ((dynamic_cast<const Chainer&> (rhs)).f2_) &&
|
||||
f2_ == ((dynamic_cast<const Chainer&> (rhs)).f1_);
|
||||
|
||||
#else
|
||||
return f1_ == ((static_cast<const Chainer&> (rhs)).f2_) &&
|
||||
f2_ == ((static_cast<const Chainer&> (rhs)).f1_);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1845,6 +1795,9 @@ namespace Loki
|
|||
#endif // FUNCTOR_INC_
|
||||
|
||||
// $Log$
|
||||
// Revision 1.22 2006/06/09 12:58:44 syntheticpp
|
||||
// simplify Functor::operator== implementation. Thanks to Eric Beyeler
|
||||
//
|
||||
// Revision 1.21 2006/06/01 12:33:05 syntheticpp
|
||||
// add operator== to Functor, initiated by Eric Beyeler
|
||||
//
|
||||
|
|
Loading…
Add table
Reference in a new issue