|
Boost Users : |
Subject: Re: [Boost-users] units and existing APIs
From: Matthias Schabel (boost_at_[hidden])
Date: 2008-11-03 17:48:10
> I would like to use boost::units in a new application that must
> interface to existing APIs that do not provide templated
> interfaces. What is the easiest way to use these existing functions
> that minimizes the copying of data from raw C pointers to a
> container that holds a specific type of boost::units?
On most compilers, the binary layout of quantity<Unit,Y> should be the
same as that of the value type, Y, so you should be able to do
something like this :
std::vector<quantity<si::energy,double> > v(100);
double *vp = reinterpret_cast<double*>(&v.front());
passing the resulting pointer to/from the legacy functions :
do_something_in_legacy_code(vp);
Naturally, you should verify that the layout is really compatible ...
Matthias
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