/*============================================================================== Copyright (c) 2005-2010 Joel de Guzman Copyright (c) 2010 Thomas Heller Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ==============================================================================*/ #ifndef BOOST_PHOENIX_CORE_FUNCTION_EQUAL_HPP #define BOOST_PHOENIX_CORE_FUNCTION_EQUAL_HPP #include #include #include #include #include #ifndef BOOST_PHOENIX_NO_VARIADIC_FUNCTION_EQUAL # include #endif namespace boost { template class weak_ptr; } namespace boost { namespace phoenix { template struct actor; namespace detail { struct compare : proto::callable { typedef bool result_type; template result_type operator()(A0 const & a0, A1 const & a1) const { return a0 == a1; } // hard wiring reference_wrapper and weak_ptr here ... // **TODO** find out why boost bind does this ... template result_type operator()( reference_wrapper const & a0 , reference_wrapper const & a1 ) const { return a0.get_pointer() == a1.get_pointer(); } template result_type operator()(weak_ptr const & a0, weak_ptr const & a1) const { return !(a0 < a1) && !(a1 < a0); } }; struct function_equal_otherwise; struct function_equal_ : proto::when< proto::if_< proto::matches() , proto::or_< proto::when< proto::terminal , compare( proto::_value , proto::call< proto::_value(proto::_state) > ) > , proto::otherwise > , proto::call > > {}; struct function_equal_otherwise : proto::callable { typedef bool result_type; result_type operator()() const { return false; } #ifdef BOOST_PHOENIX_NO_VARIADIC_FUNCTION_EQUAL template result_type operator()(Expr1 const& e1, Expr1 const& e2) const { return this->evaluate( e1 , e2 , typename proto::arity_of::type() ); } private: #include #else template result_type operator()(Expr1 const& e1, Expr1 const& e2) const { return this->evaluate( e1 , e2 , typename make_index_sequence::value>::type() ); } private: template result_type evaluate(Expr1 const& /*e1*/, Expr1 const& /*e2*/, index_sequence<>) const { return true; } template result_type evaluate(Expr1 const& e1, Expr1 const& e2, index_sequence) const { return function_equal_()(proto::child_c(e1), proto::child_c(e2)) && this->evaluate( e1 , e2 , index_sequence() ); } #endif }; } template inline bool function_equal_impl(actor const& a1, actor const& a2) { return detail::function_equal_()(a1, a2); } template inline bool function_equal(actor const& a1, actor const& a2) { return function_equal_impl(a1, a2); } }} #endif