I'm trying to figure out if boost-unit
can be used in one of my projects. With most of the functions I'm quite satisfied. But one features I'm really unable to make on my own.
Especially, I'm looking for an easy to use function that gives me the power of a certain base unit of a given quantity. It's somehow the reverse of the pow function. Actually, io.hpp
implements something similar, but I neither want to copy and paste all the stuff there, nor I want to delve into this template code.
Is there a simple workaround for the getPow
function depicted below?
#include <boost/units/systems/si.hpp>
#include <boost/units/io.hpp>
#include <iostream>
using namespace boost::units;
template<typename U, typename V>
int getPow(quantity<U>& q, V) {
int ret = 0;
// What do I have to write here?
return ret;
}
int main(int argc, char** args) {
auto q = 1.*si::meter*si::meter/si::second;
std::cout << q << std::endl;
std::cout << getPow(q, si::meter) << std::endl; // Should output 2
std::cout << getPow(q, si::second) << std::endl; // Should output -1
}