Matthias,
I appreciate your response. Yes I did not compile my example. I should
have done that. I took your example and then trimmed down the header
file so I can reproduce the error. I am not sure what is wrong here. I
get an error not because the destination type is incorrect. It does
not even reach that point. I get an error that there is no division
operator:
[storri@fedora Source]$ g++ -o boost_units boost_units.cpp
boost_units.cpp: In function int main(int, char**):
boost_units.cpp:44:39: error: no match for operator/ in 1 /
boost::units::operator-(const boost::units::quantity
I am trying to understand the dimensionality of the following two equations.
--- first equation --- example::types::radii_t val1 = 5 * example::types::radii; example::types::radii_t val2 = 4 * example::types::radii;
example::types::radii_t L1 = 1 / ( val1 - va2 );
va2->val2
This should give you a compile error anyway, since you are trying to assign a length to an inverse length...
If I was doing the dimensional analysis by hand I would see
1 / ( radii - radii )
Such that the end type would be
radii^-1
Given that end type here is the second equation:
example::types::radii_t val3 = 5 * example::types::radii; example::types::dimensionless_t val4 = 10; example::types::dimensionless_t L2 = L1 * val4 * val3;
Doing the dimensional analysis by hand I think I should see:
L2 = radii * (nothing) * radii^-1 = (nothing) or dimensionless
What Boost Units is reporting is that L2 is actually units in radii_t.
I'm not sure I believe you; the code you pasted is not compilable...did you actually compile anything?
--------- QUESTIONS --------------
Q1: How do you print out the types at compile time?
Q2: How can you confirm you have the correc power for a type? For example radii is indeed raised to the -1 power.
Using your earlier header :
#include "types.hpp"
#include <iostream> #include
using namespace myproject::types;
int main() { radii_t val1(5*radii), val2(4*radii);
//auto L1 = 1/(val1-val2); // compile time error due to failed dimensional consistency
radii_t val3(5*radii);
dimensionless_t val4 = 10; dimensionless_t L2(val3*val4/(val1-val2));
std::cout << val1 << std::endl << val2 << std::endl << val3 << std::endl << val4 << std::endl << L2 << std::endl;
return 0; }
gives
5 r 4 r 5 r 10 dimensionless 50 dimensionless