AMDG
Joseph Winston III wrote:
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?
Would a view like this be helpful?
#include
#include
#include
#include <iostream>
#include <algorithm>
using namespace boost::units;
template<class T>
class quantity_view {
struct wrap_in_quantity {
typedef T result_type;
result_type operator()(const typename T::value_type& arg) const {
return(T::from_value(arg));
}
};
public:
typedef typename T::value_type storage_value_type;
typedef T value_type;
typedef boost::transform_iterator<
wrap_in_quantity,
const storage_value_type*> iterator;
typedef iterator const_iterator;
quantity_view(const storage_value_type* impl, std::size_t size)
: impl(impl), size(size) {}
const_iterator begin() const {
return(iterator(impl));
}
const_iterator end() const {
return(iterator(impl + size));
}
private:
const storage_value_type* impl;
std::size_t size;
};
int main() {
double data[] = {1, 2, 3, 4, 5};
quantity_viewsi::time > tester(&data[0], 5);
std::ostream_iteratorsi::time > out(std::cout, "\n");
std::copy(tester.begin(), tester.end(), out);
}
In Christ,
Steven Watanabe