
On Fri, Dec 25, 2009 at 10:49 PM, Brandon Olivares
On 2009-12-25, OvermindDL1 wrote:
On Fri, Dec 25, 2009 at 11:33 AM, Brandon Olivares
wrote: As for dynamically creating types, you can do that all you wish, but you have no type information then (unless you use variant or any or something, but that has needless overhead, well, maybe not variant). That is the point of Boost.Units, to enforce that you are doing things correctly, at compile time, it optimizes completely out at run-time. OK thanks, perhaps you are right. I'm just really trying to figure out a way to make compilation a bit faster. My concern is that since these are in header files, well any source file that needs units will require
On 2009-12-25, OvermindDL1 wrote: them all to be processed again, and that is really inconvenient.
Yep, that is the major hazard of C++. If you learn how to structure things differently and use forward declarations and less class member functions (use external functions instead, ala C), that can speed up compilation tremendously.
OK, well perhaps there's another method. The primary bulk of the units I was defining were velocities. I just realized though that you can do l/t though, where l is some length and t is some time, and it doesn't have to define an existing unit.
But if I do that, I'm not sure what type to actually define the variable as.
sometype v = l/t;
What is the type in this case?
So for instance if l is light_year and t is hour, just as an example, I don't want to have to define light_year_per_hour as I was before. It's obvious that this is allowed:
quantityastronomical::light_year_unit l(3.0 * astronomical::light_years); quantitymetric::hour_unit t(8.0 * metric::hours); quantity> v(l/t);
You could just auto it. :) BOOST_AUTO(v, l/t); Then you do not need to bother figuring out what type it is, although it is your light_year_per_hour, although maybe a little more efficient representation. If you just want the type of an expression like l/t if you want to typedef it or something, then you can use BOOST_TYPEOF. It is all in the documentation. :)