|
From: Steven W. <ste...@us...> - 2007-04-12 00:39:21
|
Update of /cvsroot/boost-sandbox/boost-sandbox/boost/units In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv15994/boost-sandbox/boost/units Modified Files: system.hpp dim.hpp unit.hpp static_rational.hpp dimension.hpp Log Message: Switched metafunctions to mpl Index: unit.hpp =================================================================== RCS file: /cvsroot/boost-sandbox/boost-sandbox/boost/units/unit.hpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- unit.hpp 16 Mar 2007 18:12:43 -0000 1.1.1.1 +++ unit.hpp 12 Apr 2007 00:39:12 -0000 1.2 @@ -245,7 +245,7 @@ struct multiply_typeof_helper< unit<Dim1,homogeneous_system<System> >, unit<Dim2,homogeneous_system<System> > > { - typedef unit<typename static_multiply<Dim1,Dim2>::type,homogeneous_system<System> > type; + typedef unit<typename mpl::times<Dim1,Dim2>::type,homogeneous_system<System> > type; }; /// unit multiply typeof helper for two different homogeneous systems @@ -257,7 +257,7 @@ unit<Dim2,homogeneous_system<System2> > > { typedef unit< - typename static_multiply<Dim1,Dim2>::type, + typename mpl::times<Dim1,Dim2>::type, typename detail::multiply_systems< heterogeneous_system_view<System1, Dim1>, heterogeneous_system_view<System2, Dim2> @@ -274,7 +274,7 @@ unit<Dim2,homogeneous_system<System2> > > { typedef unit< - typename static_multiply<Dim1,Dim2>::type, + typename mpl::times<Dim1,Dim2>::type, typename detail::multiply_systems< heterogeneous_system<System1>, heterogeneous_system_view<System2, Dim2> @@ -291,7 +291,7 @@ unit<Dim2,heterogeneous_system<System2> > > { typedef unit< - typename static_multiply<Dim1,Dim2>::type, + typename mpl::times<Dim1,Dim2>::type, typename detail::multiply_systems< heterogeneous_system_view<System1, Dim1>, heterogeneous_system<System2> @@ -308,7 +308,7 @@ unit<Dim2,heterogeneous_system<System2> > > { typedef unit< - typename static_multiply<Dim1,Dim2>::type, + typename mpl::times<Dim1,Dim2>::type, typename detail::multiply_systems< heterogeneous_system<System1>, heterogeneous_system<System2> @@ -323,7 +323,7 @@ struct divide_typeof_helper< unit<Dim1,homogeneous_system<System> >, unit<Dim2,homogeneous_system<System> > > { - typedef unit<typename static_divide<Dim1,Dim2>::type,homogeneous_system<System> > type; + typedef unit<typename mpl::divides<Dim1,Dim2>::type,homogeneous_system<System> > type; }; /// unit divide typeof helper for two different homogeneous systems @@ -335,7 +335,7 @@ unit<Dim2,homogeneous_system<System2> > > { typedef unit< - typename static_divide<Dim1,Dim2>::type, + typename mpl::divides<Dim1,Dim2>::type, typename detail::divide_systems< heterogeneous_system_view<System1, Dim1>, heterogeneous_system_view<System2, Dim2> @@ -352,7 +352,7 @@ unit<Dim2,homogeneous_system<System2> > > { typedef unit< - typename static_divide<Dim1,Dim2>::type, + typename mpl::divides<Dim1,Dim2>::type, typename detail::divide_systems< heterogeneous_system<System1>, heterogeneous_system_view<System2, Dim2> @@ -369,7 +369,7 @@ unit<Dim2,heterogeneous_system<System2> > > { typedef unit< - typename static_divide<Dim1,Dim2>::type, + typename mpl::divides<Dim1,Dim2>::type, typename detail::divide_systems< heterogeneous_system_view<System1, Dim1>, heterogeneous_system<System2> @@ -386,7 +386,7 @@ unit<Dim2,heterogeneous_system<System2> > > { typedef unit< - typename static_divide<Dim1,Dim2>::type, + typename mpl::divides<Dim1,Dim2>::type, typename detail::divide_systems< heterogeneous_system<System1>, heterogeneous_system<System2> Index: static_rational.hpp =================================================================== RCS file: /cvsroot/boost-sandbox/boost-sandbox/boost/units/static_rational.hpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- static_rational.hpp 11 Apr 2007 22:21:01 -0000 1.4 +++ static_rational.hpp 12 Apr 2007 00:39:12 -0000 1.5 @@ -126,44 +126,44 @@ return T(N)/T(D); } -/// negate @c static_rational -template<integer_type N,integer_type D> -struct static_negate< static_rational<N,D> > -{ - typedef typename static_rational<-N,D>::type type; -}; - -/// add @c static_rational -template<integer_type N1,integer_type D1, - integer_type N2,integer_type D2> -struct static_add< static_rational<N1,D1>,static_rational<N2,D2> > -{ - typedef typename static_rational<N1*D2+N2*D1,D1*D2>::type type; -}; - -/// subtract @c static_rational -template<integer_type N1,integer_type D1, - integer_type N2,integer_type D2> -struct static_subtract< static_rational<N1,D1>,static_rational<N2,D2> > -{ - typedef typename static_rational<N1*D2-N2*D1,D1*D2>::type type; -}; - -/// multiply @c static_rational -template<integer_type N1,integer_type D1, - integer_type N2,integer_type D2> -struct static_multiply< static_rational<N1,D1>,static_rational<N2,D2> > -{ - typedef typename static_rational<N1*N2,D1*D2>::type type; -}; - -/// divide @c static_rational -template<integer_type N1,integer_type D1, - integer_type N2,integer_type D2> -struct static_divide< static_rational<N1,D1>,static_rational<N2,D2> > -{ - typedef typename static_rational<N1*D2,D1*N2>::type type; -}; +///// negate @c static_rational +//template<integer_type N,integer_type D> +//struct static_negate< static_rational<N,D> > +//{ +// typedef typename static_rational<-N,D>::type type; +//}; +// +///// add @c static_rational +//template<integer_type N1,integer_type D1, +// integer_type N2,integer_type D2> +//struct static_add< static_rational<N1,D1>,static_rational<N2,D2> > +//{ +// typedef typename static_rational<N1*D2+N2*D1,D1*D2>::type type; +//}; +// +///// subtract @c static_rational +//template<integer_type N1,integer_type D1, +// integer_type N2,integer_type D2> +//struct static_subtract< static_rational<N1,D1>,static_rational<N2,D2> > +//{ +// typedef typename static_rational<N1*D2-N2*D1,D1*D2>::type type; +//}; +// +///// multiply @c static_rational +//template<integer_type N1,integer_type D1, +// integer_type N2,integer_type D2> +//struct static_multiply< static_rational<N1,D1>,static_rational<N2,D2> > +//{ +// typedef typename static_rational<N1*N2,D1*D2>::type type; +//}; +// +///// divide @c static_rational +//template<integer_type N1,integer_type D1, +// integer_type N2,integer_type D2> +//struct static_divide< static_rational<N1,D1>,static_rational<N2,D2> > +//{ +// typedef typename static_rational<N1*D2,D1*N2>::type type; +//}; /// raise @c int to a @c static_rational power template<long N,long D> @@ -348,7 +348,10 @@ { template<class T0, class T1> struct apply { - typedef typename boost::units::static_add<T0, T1>::type type; + typedef typename boost::units::static_rational< + T0::Numerator*T1::Denominator+T1::Numerator*T0::Denominator, + T0::Denominator*T1::Denominator + >::type type; }; }; @@ -357,7 +360,10 @@ { template<class T0, class T1> struct apply { - typedef typename boost::units::static_subtract<T0, T1>::type type; + typedef typename boost::units::static_rational< + T0::Numerator*T1::Denominator-T1::Numerator*T0::Denominator, + T0::Denominator*T1::Denominator + >::type type; }; }; @@ -366,7 +372,10 @@ { template<class T0, class T1> struct apply { - typedef typename boost::units::static_multiply<T0, T1>::type type; + typedef typename boost::units::static_rational< + T0::Numerator*T1::Numerator, + T0::Denominator*T1::Denominator + >::type type; }; }; @@ -375,7 +384,10 @@ { template<class T0, class T1> struct apply { - typedef typename boost::units::static_divide<T0, T1>::type type; + typedef typename boost::units::static_rational< + T0::Numerator*T1::Denominator, + T0::Denominator*T1::Numerator + >::type type; }; }; @@ -384,7 +396,7 @@ { template<class T0> struct apply { - typedef typename boost::units::static_negate<T0>::type type; + typedef typename boost::units::static_rational<-T0::Numerator,T0::Denominator>::type type; }; }; Index: dimension.hpp =================================================================== RCS file: /cvsroot/boost-sandbox/boost-sandbox/boost/units/dimension.hpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- dimension.hpp 11 Apr 2007 21:25:10 -0000 1.4 +++ dimension.hpp 12 Apr 2007 00:39:12 -0000 1.5 @@ -36,6 +36,7 @@ /// Dimension lists in which all exponents resolve to zero reduce to @c dimensionless_type. struct dimensionless_type { + typedef dimensionless_type type; typedef detail::dimension_list_tag tag; typedef mpl::long_<0> size; }; @@ -72,54 +73,54 @@ public mpl::true_ { }; -// All the static_* metafunctions in this file assume -// that their parameters are sorted dimension lists. -// -// should we static assert is_dimension_list here? - -/// Negate dimension list. -template<typename DL> -struct static_negate -{ - typedef DL type; -}; - -/// Add two dimension list, only permitted if they are commensurate. -template<typename DL1,typename DL2> -struct static_add -{ - BOOST_STATIC_ASSERT((is_same<DL1,DL2>::value == true)); - typedef DL1 type; -}; - -/// Subtract two dimension sequences, only permitted if they are commensurate. -template<typename DL1,typename DL2> -struct static_subtract -{ - BOOST_STATIC_ASSERT((is_same<DL1,DL2>::value == true)); - typedef DL2 type; -}; - -/// Multiply two dimension sequences. -template<typename DL1,typename DL2> -struct static_multiply -{ - typedef typename detail::merge_dimensions<DL1,DL2>::type type; -}; - -/// Divide two dimension lists. -template<typename DL1,typename DL2> -struct static_divide -{ - typedef typename detail::merge_dimensions< - DL1, - typename detail::static_inverse_impl< - mpl::size<DL2>::value - >::template apply< - typename mpl::begin<DL2>::type - >::type - >::type type; -}; +//// All the static_* metafunctions in this file assume +//// that their parameters are sorted dimension lists. +//// +//// should we static assert is_dimension_list here? +// +///// Negate dimension list. +//template<typename DL> +//struct static_negate +//{ +// typedef DL type; +//}; +// +///// Add two dimension list, only permitted if they are commensurate. +//template<typename DL1,typename DL2> +//struct static_add +//{ +// BOOST_STATIC_ASSERT((is_same<DL1,DL2>::value == true)); +// typedef DL1 type; +//}; +// +///// Subtract two dimension sequences, only permitted if they are commensurate. +//template<typename DL1,typename DL2> +//struct static_subtract +//{ +// BOOST_STATIC_ASSERT((is_same<DL1,DL2>::value == true)); +// typedef DL2 type; +//}; +// +///// Multiply two dimension sequences. +//template<typename DL1,typename DL2> +//struct static_multiply +//{ +// typedef typename detail::merge_dimensions<DL1,DL2>::type type; +//}; +// +///// Divide two dimension lists. +//template<typename DL1,typename DL2> +//struct static_divide +//{ +// typedef typename detail::merge_dimensions< +// DL1, +// typename detail::static_inverse_impl< +// mpl::size<DL2>::value +// >::template apply< +// typename mpl::begin<DL2>::type +// >::type +// >::type type; +//}; /// Raise a dimension list to a scalar power. template<typename DL,typename Ex> @@ -210,7 +211,8 @@ template<class T0, class T1> struct apply { - typedef typename boost::units::static_add<T0, T1>::type type; + BOOST_STATIC_ASSERT((boost::is_same<T0,T1>::value == true)); + typedef T0 type; }; }; @@ -220,7 +222,8 @@ template<class T0, class T1> struct apply { - typedef typename boost::units::static_subtract<T0, T1>::type type; + BOOST_STATIC_ASSERT((boost::is_same<T0,T1>::value == true)); + typedef T0 type; }; }; @@ -230,7 +233,7 @@ template<class T0, class T1> struct apply { - typedef typename boost::units::static_multiply<T0, T1>::type type; + typedef typename boost::units::detail::merge_dimensions<T0,T1>::type type; }; }; @@ -240,17 +243,24 @@ template<class T0, class T1> struct apply { - typedef typename boost::units::static_divide<T0, T1>::type type; + typedef typename boost::units::detail::merge_dimensions< + T0, + typename boost::units::detail::static_inverse_impl< + mpl::size<T1>::value + >::template apply< + typename mpl::begin<T1>::type + >::type + >::type type; }; }; template<> struct negate_impl<boost::units::detail::dimension_list_tag> { - template<class T0, class T1> + template<class T0> struct apply { - typedef typename boost::units::static_negate<T0>::type type; + typedef T0 type; }; }; Index: system.hpp =================================================================== RCS file: /cvsroot/boost-sandbox/boost-sandbox/boost/units/system.hpp,v retrieving revision 1.1.1.2 retrieving revision 1.2 diff -u -d -r1.1.1.2 -r1.2 --- system.hpp 20 Mar 2007 04:49:08 -0000 1.1.1.2 +++ system.hpp 12 Apr 2007 00:39:12 -0000 1.2 @@ -80,19 +80,36 @@ static const bool value = true; }; -template<class S1, class E1, class E2> -struct static_add<heterogeneous_system_element<S1, E1>, heterogeneous_system_element<S1, E2> > +} // namespace units + +namespace mpl { + +template<> +struct plus_impl<boost::units::detail::heterogeneous_system_element_tag, boost::units::detail::heterogeneous_system_element_tag> { - typedef heterogeneous_system_element<S1, typename static_multiply<E1, E2>::type> type; + template<class T0, class T1> + struct apply { + BOOST_STATIC_ASSERT((boost::is_same<typename T0::tag_type, typename T1::tag_type>::value == true)); + typedef boost::units::heterogeneous_system_element<typename T0::tag_type, typename times<typename T0::value_type, typename T1::value_type>::type> type; + }; }; -template<class S1, class E1> -struct static_negate<heterogeneous_system_element<S1, E1> > +template<> +struct negate_impl<boost::units::detail::heterogeneous_system_element_tag> { - typedef typename detail::static_inverse_impl<mpl::size<E1>::value>::template apply<typename mpl::begin<E1>::type>::type inverse; - typedef heterogeneous_system_element<S1, inverse> type; + template<class T0> + struct apply { + typedef typename boost::units::detail::static_inverse_impl< + mpl::size<typename T0::value_type>::value + >::template apply<typename mpl::begin<typename T0::value_type>::type>::type inverse; + typedef boost::units::heterogeneous_system_element<typename T0::tag_type, inverse> type; + }; }; +} // namespace mpl + +namespace units { + template<class System, class Dimensions> struct heterogeneous_system_view { Index: dim.hpp =================================================================== RCS file: /cvsroot/boost-sandbox/boost-sandbox/boost/units/dim.hpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- dim.hpp 16 Mar 2007 18:12:42 -0000 1.1.1.1 +++ dim.hpp 12 Apr 2007 00:39:12 -0000 1.2 @@ -54,83 +54,159 @@ public mpl::true_ { }; -/// \brief Negate a @c dim. -/// -/// \detailed @c static_negate operation delegates to @c value_type. -template<typename T,typename V> -struct static_negate< dim<T,V> > +///// \brief Negate a @c dim. +///// +///// \detailed @c static_negate operation delegates to @c value_type. +//template<typename T,typename V> +//struct static_negate< dim<T,V> > +//{ +// typedef dim<T,typename static_negate<V>::type> type; +//}; +// +///// \brief Add two dims. +///// +///// \detailed +///// @c static_add operations on dim are only defined between dims having identical +///// @c tag_type. Operation delegates to @c value_type. +//template<typename T,typename V1,typename V2> +//struct static_add< dim<T,V1>,dim<T,V2> > +//{ +// typedef dim<T,typename static_add<V1,V2>::type> type; +//}; +// +///// \brief Subtract two dims. +///// +///// \detailed +///// @c static_subtract operations on dim are only defined between dims having identical +///// @c tag_type. Operation delegates to @c value_type. +//template<typename T,typename V1,typename V2> +//struct static_subtract< dim<T,V1>,dim<T,V2> > +//{ +// typedef dim<T,typename static_subtract<V1,V2>::type> type; +//}; +// +///// \brief Multiply a @c dim and a @c value_type. +///// +///// \detailed +///// @c static_multiply operations on @c dim are only defined between @c dim and +///// @c value_type or @c value_type and @c dim. Operation delegates to @c value_type. +//template<typename T,typename V,typename X> +//struct static_multiply< dim<T,V>,X > +//{ +// typedef dim<T,typename static_multiply<V,X>::type> type; +//}; +// +///// \brief Multipy a @c value_type and a @c dim. +///// +///// \detailed +///// @c static_multiply operations on @c dim are only defined between @c dim and +///// @c value_type or @c value_type and @c dim. Operation delegates to @c value_type. +//template<typename T,typename V,typename X> +//struct static_multiply< X,dim<T,V> > +//{ +// typedef dim<T,typename static_multiply<X,V>::type> type; +//}; +// +///// \brief Divide a @c dim by a @c value_type. +///// +///// \detailed +///// @c static_divide operations on dim are only defined between @c dim and @c value_type or +///// @c value_type and @c dim. Operation delegates to @c value_type. +//template<typename T,typename V,typename X> +//struct static_divide< dim<T,V>,X > +//{ +// typedef dim<T,typename static_divide<V,X>::type> type; +//}; +// +///// \brief Divide a @c value_type by a @c dim. +///// +///// \detailed +///// @c static_divide operations on dim are only defined between @c dim and @c value_type or +///// @c value_type and @c dim. Operation delegates to @c value_type, negating to account +///// for the resulting inverse unit tag. +//template<typename T,typename V,typename X> +//struct static_divide< X,dim<T,V> > +//{ +// typedef dim<T,typename static_negate<typename static_divide<X,V>::type>::type> type; +//}; + +} // namespace units + +namespace mpl { + +template<> +struct plus_impl<boost::units::detail::dim_tag,boost::units::detail::dim_tag> { - typedef dim<T,typename static_negate<V>::type> type; + template<class T0, class T1> + struct apply + { + BOOST_STATIC_ASSERT((boost::is_same<typename T0::tag_type,typename T1::tag_type>::value == true)); + typedef boost::units::dim<typename T0::tag_type, typename mpl::plus<typename T0::value_type, typename T1::value_type>::type> type; + }; }; -/// \brief Add two dims. -/// -/// \detailed -/// @c static_add operations on dim are only defined between dims having identical -/// @c tag_type. Operation delegates to @c value_type. -template<typename T,typename V1,typename V2> -struct static_add< dim<T,V1>,dim<T,V2> > +template<> +struct minus_impl<boost::units::detail::dim_tag,boost::units::detail::dim_tag> { - typedef dim<T,typename static_add<V1,V2>::type> type; + template<class T0, class T1> + struct apply + { + BOOST_STATIC_ASSERT((boost::is_same<typename T0::tag_type,typename T1::tag_type>::value == true)); + typedef boost::units::dim<typename T0::tag_type, typename mpl::minus<typename T0::value_type, typename T1::value_type>::type> type; + }; }; -/// \brief Subtract two dims. -/// -/// \detailed -/// @c static_subtract operations on dim are only defined between dims having identical -/// @c tag_type. Operation delegates to @c value_type. -template<typename T,typename V1,typename V2> -struct static_subtract< dim<T,V1>,dim<T,V2> > +template<> +struct times_impl<boost::units::detail::dim_tag,boost::units::detail::static_rational_tag> { - typedef dim<T,typename static_subtract<V1,V2>::type> type; + template<class T0, class T1> + struct apply + { + typedef boost::units::dim<typename T0::tag_type, typename mpl::times<typename T0::value_type, T1>::type> type; + }; }; -/// \brief Multiply a @c dim and a @c value_type. -/// -/// \detailed -/// @c static_multiply operations on @c dim are only defined between @c dim and -/// @c value_type or @c value_type and @c dim. Operation delegates to @c value_type. -template<typename T,typename V,typename X> -struct static_multiply< dim<T,V>,X > +template<> +struct times_impl<boost::units::detail::static_rational_tag,boost::units::detail::dim_tag> { - typedef dim<T,typename static_multiply<V,X>::type> type; + template<class T0, class T1> + struct apply + { + typedef boost::units::dim<typename T1::tag_type, typename mpl::times<T0, typename T1::value_type>::type> type; + }; }; -/// \brief Multipy a @c value_type and a @c dim. -/// -/// \detailed -/// @c static_multiply operations on @c dim are only defined between @c dim and -/// @c value_type or @c value_type and @c dim. Operation delegates to @c value_type. -template<typename T,typename V,typename X> -struct static_multiply< X,dim<T,V> > +template<> +struct divides_impl<boost::units::detail::dim_tag,boost::units::detail::static_rational_tag> { - typedef dim<T,typename static_multiply<X,V>::type> type; + template<class T0, class T1> + struct apply + { + typedef boost::units::dim<typename T0::tag_type, typename mpl::divides<typename T0::value_type, T1>::type> type; + }; }; -/// \brief Divide a @c dim by a @c value_type. -/// -/// \detailed -/// @c static_divide operations on dim are only defined between @c dim and @c value_type or -/// @c value_type and @c dim. Operation delegates to @c value_type. -template<typename T,typename V,typename X> -struct static_divide< dim<T,V>,X > +template<> +struct divides_impl<boost::units::detail::static_rational_tag,boost::units::detail::dim_tag> { - typedef dim<T,typename static_divide<V,X>::type> type; + template<class T0, class T1> + struct apply + { + typedef boost::units::dim<typename T1::tag_type, typename mpl::divides<T0, typename T1::value_type>::type> type; + }; }; -/// \brief Divide a @c value_type by a @c dim. -/// -/// \detailed -/// @c static_divide operations on dim are only defined between @c dim and @c value_type or -/// @c value_type and @c dim. Operation delegates to @c value_type, negating to account -/// for the resulting inverse unit tag. -template<typename T,typename V,typename X> -struct static_divide< X,dim<T,V> > +template<> +struct negate_impl<boost::units::detail::dim_tag> { - typedef dim<T,typename static_negate<typename static_divide<X,V>::type>::type> type; + template<class T0> + struct apply + { + typedef boost::units::dim<typename T0::tag_type,typename mpl::negate<typename T0::value_type>::type> type; + }; }; -} // namespace units +} // namespace mpl } // namespace boost |