Boost logo

Boost Users :

Subject: Re: [Boost-users] [units] meta_multiply units?
From: Matthias Schabel (boost_at_[hidden])
Date: 2009-09-11 14:05:33


Sorry, I should have actually checked my response... This one works :

#include <boost/units/io.hpp>
#include <boost/units/quantity.hpp>
#include <boost/units/systems/si.hpp>

#include <iostream>

using namespace boost::units;

// functor for velocity as a function of time
struct F
{
        typedef quantity<si::time> arg_type;
        typedef quantity<si::velocity> ret_type;
        
        // constant velocity
        ret_type operator()(const arg_type& t) const { return 1.0*si::meters/
si::second; }
};

template<class F>
typename multiply_typeof_helper<typename F::ret_type,typename
F::arg_type>::type
integrate(F& f,typename F::arg_type a,typename F::arg_type b)
{
        // put actual integration algorithm here...
        return f(b)*(b-a);
}

int main(void)
{
        F f;
        
        std::cout << integrate(f,0.0*si::seconds,1.0*si::seconds) << std::endl;
}



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