2009-10-05 04:29:06 +02:00
|
|
|
/*
|
|
|
|
|
MAYBE-COMPARE.hpp - guarded invocation of comparisons
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2009-10-05 04:29:06 +02:00
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2009, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2009-10-05 04:29:06 +02:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
2010-12-17 23:28:49 +01:00
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
2009-10-05 04:29:06 +02:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2009-10-05 04:29:06 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2009-10-05 04:29:06 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef LUMIERA_META_MAYBE_COMPARE_H
|
|
|
|
|
#define LUMIERA_META_MAYBE_COMPARE_H
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "lib/functor-util.hpp"
|
|
|
|
|
|
|
|
|
|
#include <tr1/functional>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace lumiera {
|
|
|
|
|
namespace typelist {
|
|
|
|
|
|
|
|
|
|
using std::tr1::function;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Trait template for invoking equality comparison.
|
|
|
|
|
* This allows to treat some types specifically....
|
|
|
|
|
*/
|
|
|
|
|
template<typename X>
|
|
|
|
|
struct Comparator
|
|
|
|
|
{
|
|
|
|
|
static bool
|
|
|
|
|
equals (X const& x1, X const& x2)
|
|
|
|
|
{
|
|
|
|
|
return x1 == x2;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** while the boost function implementation doesn't provide comparison,
|
|
|
|
|
* we'll use our private hack, which at least detects equivalence
|
|
|
|
|
* in \em some cases... */
|
|
|
|
|
template<typename SIG>
|
|
|
|
|
struct Comparator<function<SIG> >
|
|
|
|
|
{
|
|
|
|
|
static bool
|
|
|
|
|
equals (function<SIG> const& f1, function<SIG> const& f2)
|
|
|
|
|
{
|
|
|
|
|
return util::rawComparison(f1,f2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename X>
|
|
|
|
|
inline bool
|
|
|
|
|
equals_safeInvoke (X const& x1, X const& x2)
|
|
|
|
|
{
|
|
|
|
|
return Comparator<X>::equals(x1,x2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}} // namespace lumiera::typelist
|
|
|
|
|
#endif
|