Boost logo

Boost Users :

Subject: [Boost-users] [phoenix] v3 extension mechanism for template functions
From: alfC (alfredo.correa_at_[hidden])
Date: 2011-04-18 23:34:11


Hi,

 In Phoenix2 I used to have the following code to add expressions of
type pow<N>(... expr...) which where useful for expressions involving
Boost.Units. Is it possible to do something similar with Phoenix3. The
usage if macros in the tutorial examples obscures how to add template
parameters to the phoenix expression. In Phoenix2 it was straight
forward, but I can figure out how to do this in Phoenix3.

// phoenix2 code:
#include <boost/units/pow.hpp>
namespace boost{
namespace phoenix{
        template<long N>
        struct pow_eval{
                template <typename Env, typename Arg_> struct result{
                        typedef typename boost::units::power_typeof_helper<typename
boost::mpl::at_c<typename Env::args_type, 0>::type,
boost::units::static_rational<N> >::type type;
                };
                template <typename RT, typename Env, typename Arg_> static RT
eval(Env const& env, Arg_ const& arg_){
                        return boost::units::pow<N>(arg_.eval(env));
                }
        };
        template<long N, typename Arg_>
        actor<composite<pow_eval<N>, boost::fusion::vector<Arg_ > > >
        pow(actor<Arg_> const& arg_){
                return compose<pow_eval<N> >(arg_);
        }
}}

use as

 pow<3>(arg1)(l)


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