Boost.Units - Can't figure out how to use it
Hi, I've been reading the documentation for Boost.Units. I understand most of what it is saying, but am still confused on how to do many things with this library. Most of the examples are using that test_system.hpp. Does this mean that you actually have to explicitly define the units you want to use? I am confused because I see the header files for the units I want to use, e.g., light_year or astronomical_unit, but I can't figure out how to actually use them. If I use boost::units::astronomical::light_second, it cannot find it. I am able to use the SI units just fine, such as: Quantity<si::length> l = 4.0 * si::meters; But beyond that, I'm lost. I also don't know which headers I should include. I don't know if there's one or two headers that include all the basics I would need, or if I have to include each of them individually. Here's a simple program I was trying to write just to test light_second, but do not know how to make it work or which headers to include: int main() { using namespace boost::units; using namespace boost::units::astronomical; using namespace std; quantity<light_second> l1 = 4.0 * light_second; cout << "l1 = " << l1 << endl; return 0; } I'm using Boost 1.41 and I'm on Windows using Cygwin. Thanks, Brandon -- www.creatorspiritus.com Blog and forum discussing living a Christ-centered life Follow me on Twitter: http://twitter.com/devbanana Follow creatorspiritus.com on Twitter: http://twitter.com/creatorspiritus
AMDG Brandon Olivares wrote:
I've been reading the documentation for Boost.Units. I understand most of what it is saying, but am still confused on how to do many things with this library.
Most of the examples are using that test_system.hpp. Does this mean that you actually have to explicitly define the units you want to use?
I am confused because I see the header files for the units I want to use, e.g., light_year or astronomical_unit, but I can't figure out how to actually use them. If I use boost::units::astronomical::light_second, it cannot find it. I am able to use the SI units just fine, such as:
Quantity<si::length> l = 4.0 * si::meters;
But beyond that, I'm lost.
I also don't know which headers I should include. I don't know if there's one or two headers that include all the basics I would need, or if I have to include each of them individually.
There is no catch-all header.
Here's a simple program I was trying to write just to test light_second, but do not know how to make it work or which headers to include:
int main() { using namespace boost::units; using namespace boost::units::astronomical; using namespace std;
quantity<light_second> l1 = 4.0 * light_second;
cout << "l1 = " << l1 << endl;
return 0; }
#include <boost/units/base_units/astronomical/light_second.hpp> #include <boost/units/quantity.hpp> #include <boost/units/io.hpp> #include <iostream> typedef boost::units::astronomical::light_second_base_unit::unit_type light_second; int main() { using namespace boost::units; using namespace boost::units::astronomical; using namespace std; quantity<light_second> l1 = 4.0 * light_second(); cout << "l1 = " << l1 << endl; return 0; } In Christ, Steven Watanabe
Steven, Thanks a lot. I actually figured this out last night. I hadn't been paying attention to the difference between base units and units, and assumed light_seconds was a unit. I have a few other questions now though. It is able to do scaling of units I know, but let's say you want to use kilometer for instance. It appears you cannot have two length units under the same system (correct?), so would you have to create a new system just for that unit? More practically, I need to use most of the astronomical units, or at least light years, parsecs, and astronomical units. It seems I can't put them under the same system, so must I have a separate system for each of them, or am I missing something? Thanks, Brandon On 2009-12-23, Steven Watanabe wrote:
AMDG
Brandon Olivares wrote:
I've been reading the documentation for Boost.Units. I understand most of what it is saying, but am still confused on how to do many things with this library.
Most of the examples are using that test_system.hpp. Does this mean that you actually have to explicitly define the units you want to use?
I am confused because I see the header files for the units I want to use, e.g., light_year or astronomical_unit, but I can't figure out how to actually use them. If I use boost::units::astronomical::light_second, it cannot find it. I am able to use the SI units just fine, such as:
Quantity<si::length> l = 4.0 * si::meters;
But beyond that, I'm lost.
I also don't know which headers I should include. I don't know if there's one or two headers that include all the basics I would need, or if I have to include each of them individually.
There is no catch-all header.
Here's a simple program I was trying to write just to test light_second, but do not know how to make it work or which headers to include:
int main() { using namespace boost::units; using namespace boost::units::astronomical; using namespace std;
quantity<light_second> l1 = 4.0 * light_second;
cout << "l1 = " << l1 << endl;
return 0; }
#include <boost/units/base_units/astronomical/light_second.hpp> #include <boost/units/quantity.hpp> #include <boost/units/io.hpp> #include <iostream>
typedef boost::units::astronomical::light_second_base_unit::unit_type light_second;
int main() { using namespace boost::units; using namespace boost::units::astronomical; using namespace std;
quantity<light_second> l1 = 4.0 * light_second();
cout << "l1 = " << l1 << endl;
return 0; }
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Brandon www.creatorspiritus.com Blog and forum discussing living a Christ-centered life Follow me on Twitter: http://twitter.com/devbanana
AMDG Brandon Olivares wrote:
Thanks a lot. I actually figured this out last night. I hadn't been paying attention to the difference between base units and units, and assumed light_seconds was a unit.
I have a few other questions now though.
It is able to do scaling of units I know, but let's say you want to use kilometer for instance. It appears you cannot have two length units under the same system (correct?), so would you have to create a new system just for that unit?
More practically, I need to use most of the astronomical units, or at least light years, parsecs, and astronomical units. It seems I can't put them under the same system, so must I have a separate system for each of them, or am I missing something?
You can just use the ::unit_type typedef in each base unit, if you don't want to worry about systems. In Christ, Steven Watanabe
On 2009-12-23, Steven Watanabe wrote:
AMDG
Brandon Olivares wrote:
I have a few other questions now though.
It is able to do scaling of units I know, but let's say you want to use kilometer for instance. It appears you cannot have two length units under the same system (correct?), so would you have to create a new system just for that unit?
More practically, I need to use most of the astronomical units, or at least light years, parsecs, and astronomical units. It seems I can't put them under the same system, so must I have a separate system for each of them, or am I missing something?
You can just use the ::unit_type typedef in each base unit, if you don't want to worry about systems.
Thanks. Then may I ask what the use is for systems? When should one or the other be used, or what is the advantages of each? I'm sorry if my questions seem stupid, but I just started reading about this library yesterday. God bless, Brandon
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Brandon www.creatorspiritus.com Blog and forum discussing living a Christ-centered life Follow me on Twitter: http://twitter.com/devbanana
On 2009-12-23, Steven Watanabe wrote:
AMDG
Brandon Olivares wrote:
I have a few other questions now though.
It is able to do scaling of units I know, but let's say you want to use kilometer for instance. It appears you cannot have two length units under the same system (correct?), so would you have to create a new system just for that unit?
More practically, I need to use most of the astronomical units, or at least light years, parsecs, and astronomical units. It seems I can't put them under the same system, so must I have a separate system for each of them, or am I missing something?
You can just use the ::unit_type typedef in each base unit, if you don't want to worry about systems.
I have one more question about unit_type vs. system. If I want a unit composed of several base units, how would I do that if I just use unit_type as you were suggesting? For instance, right now I have something like the following, just for testing. #ifndef BOOST_UNITS_ASTRONOMICAL_LIGHT_SECOND_HPP #define BOOST_UNITS_ASTRONOMICAL_LIGHT_SECOND_HPP #include <boost/units/base_units/astronomical/light_second.hpp> #include <boost/units/base_units/si/second.hpp> #include <boost/units/physical_dimensions/length.hpp> #include <boost/units/physical_dimensions/velocity.hpp> #include <boost/units/systems/astronomical/base.hpp> namespace boost { namespace units { namespace light_second { typedef make_system< boost::units::astronomical::light_second_base_unit, boost::units::si::second_base_unit>::type system; typedef unit<dimensionless_type, system> dimensionless; typedef unit<length_dimension, system> length; typedef unit<velocity_dimension, system> velocity; BOOST_UNITS_STATIC_CONSTANT(light_second, length); BOOST_UNITS_STATIC_CONSTANT(light_seconds, length); BOOST_UNITS_STATIC_CONSTANT(light_second_per_second, velocity); BOOST_UNITS_STATIC_CONSTANT(light_seconds_per_second, velocity); } // namespace light_second } // namespace units } // namespace boost #endif Let's just say for instance that I wanted also light_year as a unit, and perhaps light_speed (light_year/year) or something like that. Using a system as above, it'd be impossible to define them in the same way, so I'm curious how you'd use unit_type as you mentioned to do this. I think you can do something like: BOOST_UNITS_STATIC_CONSTANT(light_year,boost::units::astronomical::light_yea r_base_unit::unit_type); But I don't know how you can combine two units to get velocity. Brandon
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Brandon www.creatorspiritus.com Blog and forum discussing living a Christ-centered life Follow me on Twitter: http://twitter.com/devbanana
participants (2)
-
Brandon Olivares
-
Steven Watanabe