|
Boost Users : |
Subject: Re: [Boost-users] [phoenix] v3 extension mechanism for template functions
From: alfC (alfredo.correa_at_[hidden])
Date: 2011-04-20 02:58:43
On Apr 18, 10:05 pm, Thomas Heller <thom.hel..._at_[hidden]> wrote:
> Well. the intention was to not obscure but ease the process of adding new
> expressions. Your hint has been noted, i will explain what this macro does
> with an example.
makes sense. Following your steps and the code base in
boost/phoenix/fusion/at.hpp and boost/proto/functional/fusion/at.hpp
I was able to add the pow<N>(...) expression (which works for
boost.units, and doubles), see below.
Thanks,
#include <boost/phoenix/core/limits.hpp>
#include <boost/phoenix/core/expression.hpp>
#include <boost/phoenix/core/meta_grammar.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include<boost/phoenix/core.hpp>
#include<boost/phoenix/phoenix.hpp>
#define BOOST_MPL_LIMIT_METAFUNCTION_ARITY 5
#include<boost/units/cmath.hpp>
BOOST_PHOENIX_DEFINE_EXPRESSION(
(boost)(phoenix)(pow)
, (proto::terminal<proto::_>)
(meta_grammar)
)
namespace boost{
namespace phoenix{
struct pow_eval{
BOOST_PROTO_CALLABLE() //what for?
template<typename Sig> struct result;
template<typename This, typename Seq, typename N>
struct result<This(Seq, N)>{
typedef typename boost::units::power_typeof_helper<
typename boost::remove_const<typename
boost::remove_reference<Seq>::type>::type,
boost::units::static_rational<boost::remove_reference<N>::type::value>
>::type type;
};
template<typename Seq, typename N>
typename result<pow_eval(Seq, N)>::type
operator()(Seq const &seq, N const&) const{
using namespace boost::units;
return pow<N::value>(seq);
}
};
template <typename Dummy>
struct default_actions::when<rule::pow, Dummy>
: proto::call<
pow_eval(
evaluator(proto::_child_c<1>)
, proto::_value(proto::_child_c<0>)
)
>
{};
template<long N, typename Arg>
typename expression::pow<mpl::int_<N>, Arg>::type const
pow(Arg const& arg){
return expression::pow<mpl::int_<N>, Arg>::make(mpl::int_<N>(),
arg);
}
}
}
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net