|
Boost Users : |
Subject: Re: [Boost-users] [units] easier scaled units generation
From: alfC (alfredo.correa_at_[hidden])
Date: 2010-05-04 07:24:47
> While it is not (yet) standards compliant, most current C++ compilers support this,
> which is about as easy as you can get :
>
> typedef typeof(si::giga*si::pascals) gigapascal_type;
>
ok, that is useful, I ended up doing this
namespace si{
template<class Unit> struct femto_scaled{typedef typename
make_scaled_unit<Unit, scale<10, static_rational<-15> > >::type
unit;};
template<class Unit> struct pico_scaled {typedef typename
make_scaled_unit<Unit, scale<10, static_rational<-12> > >::type
unit;};
template<class Unit> struct nano_scaled {typedef typename
make_scaled_unit<Unit, scale<10, static_rational< -9> > >::type
unit;};
template<class Unit> struct mega_scaled {typedef typename
make_scaled_unit<Unit, scale<10, static_rational< +6> > >::type
unit;};
template<class Unit> struct giga_scaled {typedef typename
make_scaled_unit<Unit, scale<10, static_rational< +9> > >::type
unit;};
//name "femto" instead of "femto_scaled" would clash with si::femto
constant
}
which works pretty well, for example
quantity<si::femto_scaled<si::time>::unit>
one_fs(1.*si::femto*si::second);
quantity<si::femto_scaled<si::time>::unit> one_s(1.*si::second);
quantity<si::nano_scaled<atomic::energy>::unit>
one_nanohartree(1.*si::nano*atomic::hartree);
quantity<si::nano_scaled<atomic::energy>::unit>
one_hartree(1.*atomic::hartree);
BUT for some strange reason doesn't completely work for this unit
(electronvolt) defined outside a system:
quantity<si::mega_scaled<atomic::electron_volt_unit>::unit>
one_Mev(1.*si::mega*atomic::eV); //works
quantity<si::mega_scaled<atomic::electron_volt_unit>::unit>
one_ev(1.*atomic::eV); //does not compile
electron_volt is defined as
namespace atomic{
struct electron_volt_base_unit : base_unit<electron_volt_base_unit,
energy_dimension, 43289> {
static const std::string name() { return "electronvolt";}
static const std::string symbol() { return "eV"; }
};
typedef electron_volt_base_unit::unit_type electron_volt_unit;
static const electron_volt_unit electron_volt, eV;
inline std::string symbol_string(const
reduce_unit<electron_volt_unit>::type&){return "eV";}
}
BOOST_UNITS_DEFINE_CONVERSION_FACTOR(
boost::units::atomic::electron_volt_base_unit,
boost::units::atomic::energy,
double, 0.03674932
);
BOOST_UNITS_DEFAULT_CONVERSION(
boost::units::atomic::electron_volt_base_unit,
boost::units::atomic::energy
);
and the compiler error is
In file included from /usr/include/boost/units/
heterogeneous_system.hpp:36,
from /usr/include/boost/units/base_unit.hpp:15,
from .atomic.hpp.cpp.cpp:14:
/usr/include/boost/units/detail/linear_algebra.hpp: In instantiation
of
boost::units::detail::determine_extra_equations_skip_zeros_impl<true,
false>::apply<boost::units::list<boost::units::list<boost::units::static_rational<0l,
1l>, boost::units::list<boost::units::static_rational<0l, 1l>,
boost::units::dimensionless_type> >,
boost::units::dimensionless_type>, 1, 1, 3,
boost::units::list<boost::units::list<boost::units::static_rational<2l,
1l>, boost::units::list<boost::units::static_rational<1l, 1l>,
boost::units::list<boost::units::static_rational<-0x00000000000000002l,
1l>, boost::units::dimensionless_type> > >,
boost::units::list<boost::units::list<boost::units::static_rational<2l,
1l>, boost::units::list<boost::units::static_rational<1l, 1l>,
boost::units::list<boost::units::static_rational<-0x00000000000000002l,
1l>, boost::units::dimensionless_type> > >,
boost::units::dimensionless_type> > >:
/usr/include/boost/units/detail/linear_algebra.hpp:264: instantiated
from boost::units::detail::determine_extra_equations<2,
false>::apply<boost::units::list<boost::units::list<boost::units::static_rational<0l,
1l>, boost::units::list<boost::units::static_rational<0l, 1l>,
boost::units::dimensionless_type> >,
boost::units::dimensionless_type>, 3,
boost::units::list<boost::units::list<boost::units::static_rational<2l,
1l>, boost::units::list<boost::units::static_rational<1l, 1l>,
boost::units::list<boost::units::static_rational<-0x00000000000000002l,
1l>, boost::units::dimensionless_type> > >,
boost::units::list<boost::units::list<boost::units::static_rational<2l,
1l>, boost::units::list<boost::units::static_rational<1l, 1l>,
boost::units::list<boost::units::static_rational<-0x00000000000000002l,
1l>, boost::units::dimensionless_type> > >,
boost::units::dimensionless_type> > >
/usr/include/boost/units/detail/linear_algebra.hpp:264: instantiated
from boost::units::detail::determine_extra_equations<3,
false>::apply<boost::units::list<boost::units::list<boost::units::static_rational<2l,
1l>, boost::units::list<boost::units::static_rational<1l, 1l>,
boost::units::list<boost::units::static_rational<-0x00000000000000002l,
1l>, boost::units::dimensionless_type> > >,
boost::units::list<boost::units::list<boost::units::static_rational<2l,
1l>, boost::units::list<boost::units::static_rational<1l, 1l>,
boost::units::list<boost::units::static_rational<-0x00000000000000002l,
1l>, boost::units::dimensionless_type> > >,
boost::units::dimensionless_type> >, 3,
boost::units::list<boost::units::list<boost::units::static_rational<2l,
1l>, boost::units::list<boost::units::static_rational<1l, 1l>,
boost::units::list<boost::units::static_rational<-0x00000000000000002l,
1l>, boost::units::dimensionless_type> > >,
boost::units::list<boost::units::list<boost::units::static_rational<2l,
1l>, boost::units::list<boost::units::static_rational<1l, 1l>,
boost::units::list<boost::units::static_rational<-0x00000000000000002l,
1l>, boost::units::dimensionless_type> > >,
boost::units::dimensionless_type> > >
/usr/include/boost/units/detail/linear_algebra.hpp:538: instantiated
from
boost::units::detail::make_square_and_invert<boost::units::list<boost::units::list<boost::units::static_rational<2l,
1l>, boost::units::list<boost::units::static_rational<1l, 1l>,
boost::units::list<boost::units::static_rational<-0x00000000000000002l,
1l>, boost::units::dimensionless_type> > >,
boost::units::list<boost::units::list<boost::units::static_rational<2l,
1l>, boost::units::list<boost::units::static_rational<1l, 1l>,
boost::units::list<boost::units::static_rational<-0x00000000000000002l,
1l>, boost::units::dimensionless_type> > >,
boost::units::dimensionless_type> > >
/usr/include/boost/units/detail/linear_algebra.hpp:828: instantiated
from
boost::units::detail::normalize_units<boost::units::list<boost::units::atomic::electron_volt_base_unit,
boost::units::list<boost::units::atomic::electron_volt_base_unit,
boost::units::dimensionless_type> > >
/usr/include/boost/units/detail/linear_algebra.hpp:1035:
instantiated from
boost::units::detail::calculate_base_unit_exponents_impl<false>::apply<boost::units::list<boost::units::atomic::electron_volt_base_unit,
boost::units::list<boost::units::atomic::electron_volt_base_unit,
boost::units::dimensionless_type> >,
boost::units::list<boost::units::dim<boost::units::length_base_dimension,
boost::units::static_rational<2l, 1l> >,
boost::units::list<boost::units::dim<boost::units::mass_base_dimension,
boost::units::static_rational<1l, 1l> >,
boost::units::list<boost::units::dim<boost::units::time_base_dimension,
boost::units::static_rational<-0x00000000000000002l, 1l> >,
boost::units::dimensionless_type> > > >
/usr/include/boost/units/detail/linear_algebra.hpp:1051:
instantiated from
boost::units::detail::calculate_base_unit_exponents<boost::units::list<boost::units::atomic::electron_volt_base_unit,
boost::units::list<boost::units::atomic::electron_volt_base_unit,
boost::units::dimensionless_type> >,
boost::units::list<boost::units::dim<boost::units::length_base_dimension,
boost::units::static_rational<2l, 1l> >,
boost::units::list<boost::units::dim<boost::units::mass_base_dimension,
boost::units::static_rational<1l, 1l> >,
boost::units::list<boost::units::dim<boost::units::time_base_dimension,
boost::units::static_rational<-0x00000000000000002l, 1l> >,
boost::units::dimensionless_type> > > >
/usr/include/boost/units/heterogeneous_system.hpp:240: instantiated
from
boost::units::detail::make_heterogeneous_system<boost::units::list<boost::units::dim<boost::units::length_base_dimension,
boost::units::static_rational<2l, 1l> >,
boost::units::list<boost::units::dim<boost::units::mass_base_dimension,
boost::units::static_rational<1l, 1l> >,
boost::units::list<boost::units::dim<boost::units::time_base_dimension,
boost::units::static_rational<-0x00000000000000002l, 1l> >,
boost::units::dimensionless_type> > >,
boost::units::homogeneous_system<boost::units::list<boost::units::atomic::electron_volt_base_unit,
boost::units::list<boost::units::atomic::electron_volt_base_unit,
boost::units::dimensionless_type> > > >
/usr/include/boost/units/unit.hpp:93: instantiated from
boost::units::reduce_unit<boost::units::unit<boost::units::list<boost::units::dim<boost::units::length_base_dimension,
boost::units::static_rational<2l, 1l> >,
boost::units::list<boost::units::dim<boost::units::mass_base_dimension,
boost::units::static_rational<1l, 1l> >,
boost::units::list<boost::units::dim<boost::units::time_base_dimension,
boost::units::static_rational<-0x00000000000000002l, 1l> >,
boost::units::dimensionless_type> > >,
boost::units::homogeneous_system<boost::units::list<boost::units::atomic::electron_volt_base_unit,
boost::units::list<boost::units::atomic::electron_volt_base_unit,
boost::units::dimensionless_type> > >, void> >
/usr/include/boost/units/detail/conversion_impl.hpp:314:
instantiated from
boost::units::detail::conversion_impl<1>::apply<boost::units::list<boost::units::heterogeneous_system_dim<boost::units::atomic::electron_volt_base_unit,
boost::units::static_rational<1l, 1l> >,
boost::units::dimensionless_type>,
boost::units::homogeneous_system<boost::units::list<boost::units::atomic::electron_volt_base_unit,
boost::units::list<boost::units::atomic::electron_volt_base_unit,
boost::units::dimensionless_type> > > >
/usr/include/boost/units/detail/conversion_impl.hpp:445:
instantiated from
boost::units::detail::conversion_factor_helper<boost::units::unit<boost::units::list<boost::units::dim<boost::units::length_base_dimension,
boost::units::static_rational<2l, 1l> >,
boost::units::list<boost::units::dim<boost::units::mass_base_dimension,
boost::units::static_rational<1l, 1l> >,
boost::units::list<boost::units::dim<boost::units::time_base_dimension,
boost::units::static_rational<-0x00000000000000002l, 1l> >,
boost::units::dimensionless_type> > >,
boost::units::heterogeneous_system<boost::units::heterogeneous_system_impl<boost::units::list<boost::units::heterogeneous_system_dim<boost::units::atomic::electron_volt_base_unit,
boost::units::static_rational<1l, 1l> >,
boost::units::dimensionless_type>,
boost::units::list<boost::units::dim<boost::units::length_base_dimension,
boost::units::static_rational<2l, 1l> >,
boost::units::list<boost::units::dim<boost::units::mass_base_dimension,
boost::units::static_rational<1l, 1l> >,
boost::units::list<boost::units::dim<boost::units::time_base_dimension,
boost::units::static_rational<-0x00000000000000002l, 1l> >,
boost::units::dimensionless_type> > >,
boost::units::dimensionless_type> >, void>,
boost::units::unit<boost::units::list<boost::units::dim<boost::units::length_base_dimension,
boost::units::static_rational<2l, 1l> >,
boost::units::list<boost::units::dim<boost::units::mass_base_dimension,
boost::units::static_rational<1l, 1l> >,
boost::units::list<boost::units::dim<boost::units::time_base_dimension,
boost::units::static_rational<-0x00000000000000002l, 1l> >,
boost::units::dimensionless_type> > >,
boost::units::heterogeneous_system<boost::units::heterogeneous_system_impl<boost::units::list<boost::units::heterogeneous_system_dim<boost::units::atomic::electron_volt_base_unit,
boost::units::static_rational<1l, 1l> >,
boost::units::dimensionless_type>,
boost::units::list<boost::units::dim<boost::units::length_base_dimension,
boost::units::static_rational<2l, 1l> >,
boost::units::list<boost::units::dim<boost::units::mass_base_dimension,
boost::units::static_rational<1l, 1l> >,
boost::units::list<boost::units::dim<boost::units::time_base_dimension,
boost::units::static_rational<-0x00000000000000002l, 1l> >,
boost::units::dimensionless_type> > >,
boost::units::list<boost::units::scale_list_dim<boost::units::scale<10l,
boost::units::static_rational<6l, 1l> > >,
boost::units::dimensionless_type> > >, void> >
/usr/include/boost/units/detail/conversion_impl.hpp:345:
instantiated from static boost::units::quantity<Unit2, T2>
boost::units::conversion_helper<boost::units::quantity<Unit1, T1>,
boost::units::quantity<Unit2, T2> >::convert(const
boost::units::quantity<Unit1, T1>&) [with Unit1 =
boost::units::unit<boost::units::list<boost::units::dim<boost::units::length_base_dimension,
boost::units::static_rational<2l, 1l> >,
boost::units::list<boost::units::dim<boost::units::mass_base_dimension,
boost::units::static_rational<1l, 1l> >,
boost::units::list<boost::units::dim<boost::units::time_base_dimension,
boost::units::static_rational<-0x00000000000000002l, 1l> >,
boost::units::dimensionless_type> > >,
boost::units::heterogeneous_system<boost::units::heterogeneous_system_impl<boost::units::list<boost::units::heterogeneous_system_dim<boost::units::atomic::electron_volt_base_unit,
boost::units::static_rational<1l, 1l> >,
boost::units::dimensionless_type>,
boost::units::list<boost::units::dim<boost::units::length_base_dimension,
boost::units::static_rational<2l, 1l> >,
boost::units::list<boost::units::dim<boost::units::mass_base_dimension,
boost::units::static_rational<1l, 1l> >,
boost::units::list<boost::units::dim<boost::units::time_base_dimension,
boost::units::static_rational<-0x00000000000000002l, 1l> >,
boost::units::dimensionless_type> > >,
boost::units::dimensionless_type> >, void>, T1 = double, Unit2 =
boost::units::unit<boost::units::list<boost::units::dim<boost::units::length_base_dimension,
boost::units::static_rational<2l, 1l> >,
boost::units::list<boost::units::dim<boost::units::mass_base_dimension,
boost::units::static_rational<1l, 1l> >,
boost::units::list<boost::units::dim<boost::units::time_base_dimension,
boost::units::static_rational<-0x00000000000000002l, 1l> >,
boost::units::dimensionless_type> > >,
boost::units::heterogeneous_system<boost::units::heterogeneous_system_impl<boost::units::list<boost::units::heterogeneous_system_dim<boost::units::atomic::electron_volt_base_unit,
boost::units::static_rational<1l, 1l> >,
boost::units::dimensionless_type>,
boost::units::list<boost::units::dim<boost::units::length_base_dimension,
boost::units::static_rational<2l, 1l> >,
boost::units::list<boost::units::dim<boost::units::mass_base_dimension,
boost::units::static_rational<1l, 1l> >,
boost::units::list<boost::units::dim<boost::units::time_base_dimension,
boost::units::static_rational<-0x00000000000000002l, 1l> >,
boost::units::dimensionless_type> > >,
boost::units::list<boost::units::scale_list_dim<boost::units::scale<10l,
boost::units::static_rational<6l, 1l> > >,
boost::units::dimensionless_type> > >, void>, T2 = double]
/usr/include/boost/units/quantity.hpp:193: instantiated from
boost::units::quantity<Unit, Y>::quantity(const
boost::units::quantity<Unit2, YY>&, typename
boost::disable_if<boost::mpl::and_<typename
boost::units::is_implicitly_convertible<Unit2, Unit>::type,
boost::units::detail::is_non_narrowing_conversion<YY, Y>,
mpl_::bool_<true>, mpl_::bool_<true>, mpl_::bool_<true> >, typename
boost::units::detail::disable_if_is_same<Unit, Unit2>::type>::type*)
[with Unit2 =
boost::units::unit<boost::units::list<boost::units::dim<boost::units::length_base_dimension,
boost::units::static_rational<2l, 1l> >,
boost::units::list<boost::units::dim<boost::units::mass_base_dimension,
boost::units::static_rational<1l, 1l> >,
boost::units::list<boost::units::dim<boost::units::time_base_dimension,
boost::units::static_rational<-0x00000000000000002l, 1l> >,
boost::units::dimensionless_type> > >,
boost::units::heterogeneous_system<boost::units::heterogeneous_system_impl<boost::units::list<boost::units::heterogeneous_system_dim<boost::units::atomic::electron_volt_base_unit,
boost::units::static_rational<1l, 1l> >,
boost::units::dimensionless_type>,
boost::units::list<boost::units::dim<boost::units::length_base_dimension,
boost::units::static_rational<2l, 1l> >,
boost::units::list<boost::units::dim<boost::units::mass_base_dimension,
boost::units::static_rational<1l, 1l> >,
boost::units::list<boost::units::dim<boost::units::time_base_dimension,
boost::units::static_rational<-0x00000000000000002l, 1l> >,
boost::units::dimensionless_type> > >,
boost::units::dimensionless_type> >, void>, YY = double, Unit =
boost::units::unit<boost::units::list<boost::units::dim<boost::units::length_base_dimension,
boost::units::static_rational<2l, 1l> >,
boost::units::list<boost::units::dim<boost::units::mass_base_dimension,
boost::units::static_rational<1l, 1l> >,
boost::units::list<boost::units::dim<boost::units::time_base_dimension,
boost::units::static_rational<-0x00000000000000002l, 1l> >,
boost::units::dimensionless_type> > >,
boost::units::heterogeneous_system<boost::units::heterogeneous_system_impl<boost::units::list<boost::units::heterogeneous_system_dim<boost::units::atomic::electron_volt_base_unit,
boost::units::static_rational<1l, 1l> >,
boost::units::dimensionless_type>,
boost::units::list<boost::units::dim<boost::units::length_base_dimension,
boost::units::static_rational<2l, 1l> >,
boost::units::list<boost::units::dim<boost::units::mass_base_dimension,
boost::units::static_rational<1l, 1l> >,
boost::units::list<boost::units::dim<boost::units::time_base_dimension,
boost::units::static_rational<-0x00000000000000002l, 1l> >,
boost::units::dimensionless_type> > >,
boost::units::list<boost::units::scale_list_dim<boost::units::scale<10l,
boost::units::static_rational<6l, 1l> > >,
boost::units::dimensionless_type> > >, void>, Y = double]
.atomic.hpp.cpp.cpp:416: instantiated from here
/usr/include/boost/units/detail/linear_algebra.hpp:197: error: no type
named item in struct boost::units::dimensionless_type
compilation terminated due to -Wfatal-errors.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net