// mcs::units - A C++ library for zero-overhead // dimensional analysis and unit manipulation/conversion. // // Copyright (C) 2003-2006 Matthias Christian Schabel // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // unit_example_1.cpp // need to link with libboost_regex to get demangling functionality #define MCS_USE_DEMANGLING #include #include #include #include using namespace boost::units; struct length_tag : public ordinal<1> { }; struct mass_tag : public ordinal<2> { }; struct time_tag : public ordinal<3> { }; typedef boost::mpl::list< dim< length_tag,static_rational<1> > > length_type; typedef boost::mpl::list< dim< mass_tag,static_rational<1> > > mass_type; typedef boost::mpl::list< dim< time_tag,static_rational<1> > > time_type; int main(void) { typedef boost::mpl::list< dim< length_tag,static_rational<1> > > length_type; typedef boost::mpl::list< dim< mass_tag,static_rational<1> > > mass_type; typedef boost::mpl::list< dim< time_tag,static_rational<1> > > time_type; typedef boost::mpl::list< dim< mass_tag,static_rational<1> >, dim< length_tag,static_rational<2> >, dim< time_tag,static_rational<2> > > energy_type; std::cout << simplify_mpl_typename(length_type()) << std::endl << simplify_mpl_typename(mass_type()) << std::endl << simplify_mpl_typename(time_type()) << std::endl << simplify_mpl_typename(energy_type()) << std::endl; typedef static_multiply::type LM_type; typedef static_divide::type L_T_type; typedef static_multiply::type, static_divide::type>::type>::type V_type; std::cout << simplify_mpl_typename(LM_type()) << std::endl << simplify_mpl_typename(L_T_type()) << std::endl << simplify_mpl_typename(V_type()) << std::endl; return 0; }