|
Boost-Commit : |
From: steven_at_[hidden]
Date: 2008-07-08 12:48:38
Author: steven_watanabe
Date: 2008-07-08 12:48:36 EDT (Tue, 08 Jul 2008)
New Revision: 47235
URL: http://svn.boost.org/trac/boost/changeset/47235
Log:
Merge optimizations and sun fixes from the trunk
Text files modified:
branches/release/boost/units/absolute.hpp | 1
branches/release/boost/units/conversion.hpp | 4
branches/release/boost/units/derived_dimension.hpp | 74 +-
branches/release/boost/units/detail/absolute_impl.hpp | 16
branches/release/boost/units/detail/conversion_impl.hpp | 182 ++----
branches/release/boost/units/detail/dimension_impl.hpp | 209 +++----
branches/release/boost/units/detail/heterogeneous_conversion.hpp | 104 +--
branches/release/boost/units/detail/linear_algebra.hpp | 1069 ++++++++++++++++++---------------------
branches/release/boost/units/detail/push_front_if.hpp | 7
branches/release/boost/units/detail/push_front_or_add.hpp | 13
branches/release/boost/units/detail/sort.hpp | 127 +---
branches/release/boost/units/detail/unscale.hpp | 8
branches/release/boost/units/dimension.hpp | 14
branches/release/boost/units/heterogeneous_system.hpp | 28
branches/release/boost/units/io.hpp | 32
branches/release/boost/units/lambda.hpp | 2
branches/release/boost/units/make_system.hpp | 20
branches/release/boost/units/quantity.hpp | 90 +++
branches/release/boost/units/unit.hpp | 36
19 files changed, 976 insertions(+), 1060 deletions(-)
Modified: branches/release/boost/units/absolute.hpp
==============================================================================
--- branches/release/boost/units/absolute.hpp (original)
+++ branches/release/boost/units/absolute.hpp 2008-07-08 12:48:36 EDT (Tue, 08 Jul 2008)
@@ -133,6 +133,7 @@
reduce_unit<From::unit_type>::type, \
reduce_unit<To::unit_type>::type> \
{ \
+ static const bool is_defined = true; \
typedef type_ type; \
static type value() { return(value_); } \
}; \
Modified: branches/release/boost/units/conversion.hpp
==============================================================================
--- branches/release/boost/units/conversion.hpp (original)
+++ branches/release/boost/units/conversion.hpp 2008-07-08 12:48:36 EDT (Tue, 08 Jul 2008)
@@ -70,6 +70,7 @@
template<> \
struct base_unit_converter<Source, reduce_unit<Destination::unit_type>::type> \
{ \
+ static const bool is_defined = true; \
typedef type_ type; \
static type value() { return(value_); } \
}; \
@@ -95,6 +96,7 @@
BOOST_UNITS_MAKE_HETEROGENEOUS_UNIT(Destination, typename Source::dimension_type)\
> \
{ \
+ static const bool is_defined = true; \
typedef type_ type; \
static type value() { return(value_); } \
}; \
@@ -112,6 +114,7 @@
template<> \
struct unscaled_get_default_conversion<unscale<Source>::type> \
{ \
+ static const bool is_defined = true; \
typedef Dest type; \
}; \
} \
@@ -130,6 +133,7 @@
template<BOOST_PP_SEQ_ENUM(Params)> \
struct unscaled_get_default_conversion<Source> \
{ \
+ static const bool is_defined = true; \
typedef Dest type; \
}; \
} \
Modified: branches/release/boost/units/derived_dimension.hpp
==============================================================================
--- branches/release/boost/units/derived_dimension.hpp (original)
+++ branches/release/boost/units/derived_dimension.hpp 2008-07-08 12:48:36 EDT (Tue, 08 Jul 2008)
@@ -11,8 +11,6 @@
#ifndef BOOST_UNITS_DERIVED_DIMENSION_HPP
#define BOOST_UNITS_DERIVED_DIMENSION_HPP
-#include <boost/mpl/list.hpp>
-
#include <boost/units/dim.hpp>
#include <boost/units/dimension.hpp>
#include <boost/units/static_rational.hpp>
@@ -38,14 +36,14 @@
typedef detail::unspecified type;
#else
typedef typename
- make_dimension_list< mpl::list< dim< DT1,static_rational<E1> >,
- dim< DT2,static_rational<E2> >,
- dim< DT3,static_rational<E3> >,
- dim< DT4,static_rational<E4> >,
- dim< DT5,static_rational<E5> >,
- dim< DT6,static_rational<E6> >,
- dim< DT7,static_rational<E7> >,
- dim< DT8,static_rational<E8> > > >::type type;
+ make_dimension_list< list< dim< DT1,static_rational<E1> >,
+ list< dim< DT2,static_rational<E2> >,
+ list< dim< DT3,static_rational<E3> >,
+ list< dim< DT4,static_rational<E4> >,
+ list< dim< DT5,static_rational<E5> >,
+ list< dim< DT6,static_rational<E6> >,
+ list< dim< DT7,static_rational<E7> >,
+ list< dim< DT8,static_rational<E8> >, dimensionless_type > > > > > > > > >::type type;
#endif
};
@@ -62,7 +60,7 @@
dimensionless_type,0>
{
typedef typename
- make_dimension_list< mpl::list< dim< DT1,static_rational<E1> > > >::type type;
+ make_dimension_list< list< dim< DT1,static_rational<E1> >, dimensionless_type > >::type type;
};
/// INTERNAL ONLY
@@ -79,8 +77,8 @@
dimensionless_type,0>
{
typedef typename
- make_dimension_list< mpl::list< dim< DT1,static_rational<E1> >,
- dim< DT2,static_rational<E2> > > >::type type;
+ make_dimension_list< list< dim< DT1,static_rational<E1> >,
+ list< dim< DT2,static_rational<E2> >, dimensionless_type > > >::type type;
};
/// INTERNAL ONLY
@@ -98,9 +96,9 @@
dimensionless_type,0>
{
typedef typename
- make_dimension_list< mpl::list< dim< DT1,static_rational<E1> >,
- dim< DT2,static_rational<E2> >,
- dim< DT3,static_rational<E3> > > >::type type;
+ make_dimension_list< list< dim< DT1,static_rational<E1> >,
+ list< dim< DT2,static_rational<E2> >,
+ list< dim< DT3,static_rational<E3> >, dimensionless_type > > > >::type type;
};
/// INTERNAL ONLY
@@ -119,10 +117,10 @@
dimensionless_type,0>
{
typedef typename
- make_dimension_list< mpl::list< dim< DT1,static_rational<E1> >,
- dim< DT2,static_rational<E2> >,
- dim< DT3,static_rational<E3> >,
- dim< DT4,static_rational<E4> > > >::type type;
+ make_dimension_list< list< dim< DT1,static_rational<E1> >,
+ list< dim< DT2,static_rational<E2> >,
+ list< dim< DT3,static_rational<E3> >,
+ list< dim< DT4,static_rational<E4> >, dimensionless_type > > > > >::type type;
};
/// INTERNAL ONLY
@@ -142,11 +140,11 @@
dimensionless_type,0>
{
typedef typename
- make_dimension_list< mpl::list< dim< DT1,static_rational<E1> >,
- dim< DT2,static_rational<E2> >,
- dim< DT3,static_rational<E3> >,
- dim< DT4,static_rational<E4> >,
- dim< DT5,static_rational<E5> > > >::type type;
+ make_dimension_list< list< dim< DT1,static_rational<E1> >,
+ list< dim< DT2,static_rational<E2> >,
+ list< dim< DT3,static_rational<E3> >,
+ list< dim< DT4,static_rational<E4> >,
+ list< dim< DT5,static_rational<E5> >, dimensionless_type > > > > > >::type type;
};
/// INTERNAL ONLY
@@ -167,12 +165,12 @@
dimensionless_type,0>
{
typedef typename
- make_dimension_list< mpl::list< dim< DT1,static_rational<E1> >,
- dim< DT2,static_rational<E2> >,
- dim< DT3,static_rational<E3> >,
- dim< DT4,static_rational<E4> >,
- dim< DT5,static_rational<E5> >,
- dim< DT6,static_rational<E6> > > >::type type;
+ make_dimension_list< list< dim< DT1,static_rational<E1> >,
+ list< dim< DT2,static_rational<E2> >,
+ list< dim< DT3,static_rational<E3> >,
+ list< dim< DT4,static_rational<E4> >,
+ list< dim< DT5,static_rational<E5> >,
+ list< dim< DT6,static_rational<E6> >, dimensionless_type > > > > > > >::type type;
};
/// INTERNAL ONLY
@@ -194,13 +192,13 @@
dimensionless_type,0>
{
typedef typename
- make_dimension_list< mpl::list< dim< DT1,static_rational<E1> >,
- dim< DT2,static_rational<E2> >,
- dim< DT3,static_rational<E3> >,
- dim< DT4,static_rational<E4> >,
- dim< DT5,static_rational<E5> >,
- dim< DT6,static_rational<E6> >,
- dim< DT7,static_rational<E7> > > >::type type;
+ make_dimension_list< list< dim< DT1,static_rational<E1> >,
+ list< dim< DT2,static_rational<E2> >,
+ list< dim< DT3,static_rational<E3> >,
+ list< dim< DT4,static_rational<E4> >,
+ list< dim< DT5,static_rational<E5> >,
+ list< dim< DT6,static_rational<E6> >,
+ list< dim< DT7,static_rational<E7> >, dimensionless_type > > > > > > > >::type type;
};
} // namespace units
Modified: branches/release/boost/units/detail/absolute_impl.hpp
==============================================================================
--- branches/release/boost/units/detail/absolute_impl.hpp (original)
+++ branches/release/boost/units/detail/absolute_impl.hpp 2008-07-08 12:48:36 EDT (Tue, 08 Jul 2008)
@@ -13,8 +13,6 @@
#include <iosfwd>
-#include <boost/type_traits/is_base_and_derived.hpp>
-
#include <boost/units/config.hpp>
#include <boost/units/conversion.hpp>
#include <boost/units/heterogeneous_system.hpp>
@@ -33,7 +31,9 @@
namespace detail {
-struct undefined_affine_conversion_base { };
+struct undefined_affine_conversion_base {
+ static const bool is_defined = false;
+};
} // namespace detail
@@ -89,14 +89,8 @@
return(
to_quantity_type::from_value(
detail::affine_conversion_impl<
- !boost::is_base_and_derived<
- detail::undefined_affine_conversion_base,
- affine_conversion_helper<typename reduce_unit<Unit1>::type, typename reduce_unit<Unit2>::type>
- >::value,
- !boost::is_base_and_derived<
- detail::undefined_affine_conversion_base,
- affine_conversion_helper<typename reduce_unit<Unit2>::type, typename reduce_unit<Unit1>::type>
- >::value
+ affine_conversion_helper<typename reduce_unit<Unit1>::type, typename reduce_unit<Unit2>::type>::is_defined,
+ affine_conversion_helper<typename reduce_unit<Unit2>::type, typename reduce_unit<Unit1>::type>::is_defined
>::template apply<Unit1, Unit2, T1, T2>::value(source.value())
)
);
Modified: branches/release/boost/units/detail/conversion_impl.hpp
==============================================================================
--- branches/release/boost/units/detail/conversion_impl.hpp (original)
+++ branches/release/boost/units/detail/conversion_impl.hpp 2008-07-08 12:48:36 EDT (Tue, 08 Jul 2008)
@@ -12,14 +12,10 @@
#define BOOST_UNITS_DETAIL_CONVERSION_IMPL_HPP
#include <boost/mpl/bool.hpp>
-#include <boost/mpl/size.hpp>
-#include <boost/mpl/begin.hpp>
-#include <boost/mpl/next.hpp>
-#include <boost/mpl/deref.hpp>
+#include <boost/mpl/and.hpp>
#include <boost/mpl/divides.hpp>
#include <boost/preprocessor/seq/enum.hpp>
#include <boost/type_traits/is_same.hpp>
-#include <boost/type_traits/is_base_and_derived.hpp>
#include <boost/units/heterogeneous_system.hpp>
#include <boost/units/homogeneous_system.hpp>
@@ -49,10 +45,14 @@
}
/// INTERNAL ONLY
-struct undefined_base_unit_converter_base { };
+struct undefined_base_unit_converter_base {
+ static const bool is_defined = false;
+};
/// INTERNAL ONLY
-struct no_default_conversion { };
+struct no_default_conversion {
+ static const bool is_defined = false;
+};
/// INTERNAL ONLY
template<class BaseUnit>
@@ -89,7 +89,7 @@
struct get_default_conversion
{
typedef typename unscaled_get_default_conversion_impl<
- !boost::is_base_and_derived<no_default_conversion, unscaled_get_default_conversion<typename unscale<BaseUnit>::type> >::value
+ unscaled_get_default_conversion<typename unscale<BaseUnit>::type>::is_defined
>::template apply<BaseUnit>::type type;
};
@@ -103,12 +103,14 @@
/// INTERNAL ONLY
template<class Source, class Dest>
-struct base_unit_converter_base : undefined_base_unit_converter_base { };
+struct base_unit_converter_base : undefined_base_unit_converter_base {
+};
/// INTERNAL ONLY
template<class Source>
struct base_unit_converter_base<Source, BOOST_UNITS_MAKE_HETEROGENEOUS_UNIT(Source, typename Source::dimension_type)>
{
+ static const bool is_defined = true;
typedef one type;
static type value() {
return(one());
@@ -121,45 +123,22 @@
namespace detail {
-template<bool is_defined>
-struct do_call_base_unit_converter_impl;
-
-template<>
-struct do_call_base_unit_converter_impl<true>
-{
- template<class Source, class Dest>
- struct apply : base_unit_converter<Source, Dest> { };
-};
-
-template<>
-struct do_call_base_unit_converter_impl<false>
-{
- template<class Source, class Dest>
- struct apply {
- typedef select_base_unit_converter<typename unscale<Source>::type, typename unscale<Dest>::type> selector;
- typedef typename selector::source_type source_type;
- typedef typename selector::destination_type destination_type;
- typedef base_unit_converter<source_type, destination_type> converter;
- typedef typename mpl::divides<typename get_scale_list<Source>::type, typename get_scale_list<source_type>::type>::type source_factor;
- typedef typename mpl::divides<typename get_scale_list<Dest>::type, typename get_scale_list<destination_type>::type>::type destination_factor;
- typedef typename mpl::divides<source_factor, destination_factor>::type factor;
- typedef eval_scale_list<factor> eval_factor;
- typedef typename multiply_typeof_helper<typename converter::type, typename eval_factor::type>::type type;
- static type value()
- {
- return(converter::value() * eval_factor::value());
- }
- };
-};
-
template<class Source, class Dest>
-struct do_call_base_unit_converter :
- do_call_base_unit_converter_impl<
- !boost::is_base_and_derived<
- undefined_base_unit_converter_base,
- base_unit_converter<Source, Dest>
- >::value
- >::template apply<Source, Dest> {};
+struct do_call_base_unit_converter {
+ typedef select_base_unit_converter<typename unscale<Source>::type, typename unscale<Dest>::type> selector;
+ typedef typename selector::source_type source_type;
+ typedef typename selector::destination_type destination_type;
+ typedef base_unit_converter<source_type, destination_type> converter;
+ typedef typename mpl::divides<typename get_scale_list<Source>::type, typename get_scale_list<source_type>::type>::type source_factor;
+ typedef typename mpl::divides<typename get_scale_list<Dest>::type, typename get_scale_list<destination_type>::type>::type destination_factor;
+ typedef typename mpl::divides<source_factor, destination_factor>::type factor;
+ typedef eval_scale_list<factor> eval_factor;
+ typedef typename multiply_typeof_helper<typename converter::type, typename eval_factor::type>::type type;
+ static type value()
+ {
+ return(converter::value() * eval_factor::value());
+ }
+};
template<bool forward_is_defined, bool reverse_is_defined>
struct call_base_unit_converter_base_unit_impl;
@@ -168,7 +147,8 @@
struct call_base_unit_converter_base_unit_impl<true, true>
{
template<class Source, class Dest>
- struct apply : do_call_base_unit_converter<Source, typename Dest::unit_type>
+ struct apply
+ : do_call_base_unit_converter<Source, typename Dest::unit_type>
{
};
};
@@ -177,7 +157,8 @@
struct call_base_unit_converter_base_unit_impl<true, false>
{
template<class Source, class Dest>
- struct apply : do_call_base_unit_converter<Source, typename Dest::unit_type>
+ struct apply
+ : do_call_base_unit_converter<Source, typename Dest::unit_type>
{
};
};
@@ -229,11 +210,11 @@
template<class Begin>
struct apply
{
- typedef typename mpl::deref<Begin>::type source_pair;
+ typedef typename Begin::item source_pair;
typedef typename source_pair::value_type exponent;
typedef typename source_pair::tag_type source;
typedef typename get_default_conversion<source>::type new_source;
- typedef typename get_default_conversion_impl<N-1>::template apply<typename mpl::next<Begin>::type> next_iteration;
+ typedef typename get_default_conversion_impl<N-1>::template apply<typename Begin::next> next_iteration;
typedef typename multiply_typeof_helper<typename power_typeof_helper<new_source, exponent>::type, typename next_iteration::unit_type>::type unit_type;
typedef call_base_unit_converter<source, new_source> conversion;
typedef typename multiply_typeof_helper<typename conversion::type, typename next_iteration::type>::type type;
@@ -264,7 +245,8 @@
struct call_base_unit_converter_impl<true>
{
template<class Source, class Dest>
- struct apply : do_call_base_unit_converter<Source, Dest>
+ struct apply
+ : do_call_base_unit_converter<Source, Dest>
{
};
};
@@ -276,7 +258,7 @@
struct apply {
typedef typename reduce_unit<typename get_default_conversion<Source>::type>::type new_source;
typedef typename Dest::system_type::type system_list;
- typedef typename get_default_conversion_impl<mpl::size<system_list>::value>::template apply<typename mpl::begin<system_list>::type> impl;
+ typedef typename get_default_conversion_impl<system_list::size::value>::template apply<system_list> impl;
typedef typename impl::unit_type new_dest;
typedef call_base_unit_converter<Source, new_source> start;
typedef conversion_factor_helper<new_source, new_dest> conversion;
@@ -293,36 +275,22 @@
};
};
-template<class Source, class Dest>
-struct base_unit_converter_scaled_is_undefined :
- boost::is_base_and_derived<
- undefined_base_unit_converter_base,
- base_unit_converter<
- typename select_base_unit_converter<typename unscale<Source>::type, typename unscale<Dest>::type>::source_type,
- typename select_base_unit_converter<typename unscale<Source>::type, typename unscale<Dest>::type>::destination_type
- >
- > {};
-
-template<class Source, class Dest>
-struct base_unit_converter_is_undefined :
- mpl::and_<
- boost::is_base_and_derived<
- undefined_base_unit_converter_base,
- base_unit_converter<Source, Dest>
- >,
- base_unit_converter_scaled_is_undefined<Source, Dest>
- > {};
+#define BOOST_UNITS_DETAIL_BASE_UNIT_CONVERTER_IS_DEFINED(Source, Dest)\
+ base_unit_converter<\
+ typename select_base_unit_converter<typename unscale<Source>::type, typename unscale<Dest>::type>::source_type,\
+ typename select_base_unit_converter<typename unscale<Source>::type, typename unscale<Dest>::type>::destination_type\
+ >::is_defined
template<class Source, class Dest>
-struct call_base_unit_converter : call_base_unit_converter_impl<!base_unit_converter_is_undefined<Source, Dest>::value>::template apply<Source, Dest>
+struct call_base_unit_converter : call_base_unit_converter_impl<BOOST_UNITS_DETAIL_BASE_UNIT_CONVERTER_IS_DEFINED(Source, Dest)>::template apply<Source, Dest>
{
};
template<class Source, class Dest>
struct call_base_unit_converter<Source, BOOST_UNITS_MAKE_HETEROGENEOUS_UNIT(Dest, typename Source::dimension_type)> :
call_base_unit_converter_base_unit_impl<
- !base_unit_converter_is_undefined<Source, typename Dest::unit_type>::value,
- !base_unit_converter_is_undefined<Dest, typename Source::unit_type>::value
+ BOOST_UNITS_DETAIL_BASE_UNIT_CONVERTER_IS_DEFINED(Source, typename Dest::unit_type),
+ BOOST_UNITS_DETAIL_BASE_UNIT_CONVERTER_IS_DEFINED(Dest, typename Source::unit_type)
>::template apply<Source, Dest>
{
};
@@ -334,10 +302,10 @@
struct apply
{
typedef typename conversion_impl<N-1>::template apply<
- typename mpl::next<Begin>::type,
+ typename Begin::next,
DestinationSystem
> next_iteration;
- typedef typename mpl::deref<Begin>::type unit_pair;
+ typedef typename Begin::item unit_pair;
typedef typename unit_pair::tag_type unit;
typedef typename unit::dimension_type dimensions;
typedef typename reduce_unit<units::unit<dimensions, DestinationSystem> >::type reduced_unit;
@@ -374,8 +342,8 @@
static destination_type convert(const quantity<unit<D, homogeneous_system<L1> >, T1>& source)
{
return(destination_type::from_value(source.value() *
- detail::conversion_impl<mpl::size<unit_list>::value>::template apply<
- typename mpl::begin<unit_list>::type,
+ detail::conversion_impl<unit_list::size::value>::template apply<
+ unit_list,
homogeneous_system<L2>
>::value()
));
@@ -392,8 +360,8 @@
static destination_type convert(const quantity<unit<D, heterogeneous_system<L1> >, T1>& source)
{
return(destination_type::from_value(source.value() *
- detail::conversion_impl<mpl::size<typename L1::type>::value>::template apply<
- typename mpl::begin<typename L1::type>::type,
+ detail::conversion_impl<L1::type::size::value>::template apply<
+ typename L1::type,
homogeneous_system<L2>
>::value() *
eval_scale_list<typename L1::scale>::value()
@@ -414,8 +382,8 @@
static destination_type convert(const quantity<unit<D, homogeneous_system<L1> >, T1>& source)
{
return(destination_type::from_value(source.value() /
- (detail::conversion_impl<mpl::size<typename L2::type>::value>::template apply<
- typename mpl::begin<typename L2::type>::type,
+ (detail::conversion_impl<L2::type::size::value>::template apply<
+ typename L2::type,
homogeneous_system<L1>
>::value() *
eval_scale_list<typename L2::scale>::value()
@@ -435,13 +403,13 @@
/// INTERNAL ONLY
typedef quantity<unit<D, heterogeneous_system<S2> >, T2> destination_type;
/// INTERNAL ONLY
- typedef typename detail::extract_base_units<mpl::size<typename S1::type>::value>::template apply<
- typename mpl::begin<typename S1::type>::type,
- mpl::list0<>
+ typedef typename detail::extract_base_units<S1::type::size::value>::template apply<
+ typename S1::type,
+ dimensionless_type
>::type from_base_units;
/// INTERNAL ONLY
- typedef typename detail::extract_base_units<mpl::size<typename S2::type>::value>::template apply<
- typename mpl::begin<typename S2::type>::type,
+ typedef typename detail::extract_base_units<S2::type::size::value>::template apply<
+ typename S2::type,
from_base_units
>::type all_base_units;
/// INTERNAL ONLY
@@ -451,12 +419,12 @@
static destination_type convert(const source_type& source)
{
return(destination_type::from_value(source.value() *
- (detail::conversion_impl<mpl::size<typename S1::type>::value>::template apply<
- typename mpl::begin<typename S1::type>::type,
+ (detail::conversion_impl<S1::type::size::value>::template apply<
+ typename S1::type,
system
>::value() * eval_scale_list<result_scale>::value() /
- detail::conversion_impl<mpl::size<typename S2::type>::value>::template apply<
- typename mpl::begin<typename S2::type>::type,
+ detail::conversion_impl<S2::type::size::value>::template apply<
+ typename S2::type,
system
>::value()
)
@@ -474,8 +442,8 @@
{
typedef typename reduce_unit<unit<D, homogeneous_system<L1> > >::type source_unit;
typedef typename source_unit::system_type::type unit_list;
- typedef typename detail::conversion_impl<mpl::size<unit_list>::value>::template apply<
- typename mpl::begin<unit_list>::type,
+ typedef typename detail::conversion_impl<unit_list::size::value>::template apply<
+ unit_list,
homogeneous_system<L2>
> impl;
typedef typename impl::type type;
@@ -488,8 +456,8 @@
template<class D, class L1, class L2>
struct conversion_factor_helper<unit<D, heterogeneous_system<L1> >, unit<D, homogeneous_system<L2> > >
{
- typedef typename detail::conversion_impl<mpl::size<typename L1::type>::value>::template apply<
- typename mpl::begin<typename L1::type>::type,
+ typedef typename detail::conversion_impl<L1::type::size::value>::template apply<
+ typename L1::type,
homogeneous_system<L2>
> impl;
typedef eval_scale_list<typename L1::scale> scale;
@@ -506,8 +474,8 @@
template<class D, class L1, class L2>
struct conversion_factor_helper<unit<D, homogeneous_system<L1> >, unit<D, heterogeneous_system<L2> > >
{
- typedef typename detail::conversion_impl<mpl::size<typename L2::type>::value>::template apply<
- typename mpl::begin<typename L2::type>::type,
+ typedef typename detail::conversion_impl<L2::type::size::value>::template apply<
+ typename L2::type,
homogeneous_system<L1>
> impl;
typedef eval_scale_list<typename L2::scale> scale;
@@ -524,23 +492,23 @@
struct conversion_factor_helper<unit<D, heterogeneous_system<S1> >, unit<D, heterogeneous_system<S2> > >
{
/// INTERNAL ONLY
- typedef typename detail::extract_base_units<mpl::size<typename S1::type>::value>::template apply<
- typename mpl::begin<typename S1::type>::type,
- mpl::list0<>
+ typedef typename detail::extract_base_units<S1::type::size::value>::template apply<
+ typename S1::type,
+ dimensionless_type
>::type from_base_units;
/// INTERNAL ONLY
- typedef typename detail::extract_base_units<mpl::size<typename S2::type>::value>::template apply<
- typename mpl::begin<typename S2::type>::type,
+ typedef typename detail::extract_base_units<S2::type::size::value>::template apply<
+ typename S2::type,
from_base_units
>::type all_base_units;
/// INTERNAL ONLY
typedef typename detail::make_homogeneous_system<all_base_units>::type system;
- typedef typename detail::conversion_impl<mpl::size<typename S1::type>::value>::template apply<
- typename mpl::begin<typename S1::type>::type,
+ typedef typename detail::conversion_impl<S1::type::size::value>::template apply<
+ typename S1::type,
system
> conversion1;
- typedef typename detail::conversion_impl<mpl::size<typename S2::type>::value>::template apply<
- typename mpl::begin<typename S2::type>::type,
+ typedef typename detail::conversion_impl<S2::type::size::value>::template apply<
+ typename S2::type,
system
> conversion2;
typedef eval_scale_list<typename mpl::divides<typename S1::scale, typename S2::scale>::type> scale;
Modified: branches/release/boost/units/detail/dimension_impl.hpp
==============================================================================
--- branches/release/boost/units/detail/dimension_impl.hpp (original)
+++ branches/release/boost/units/detail/dimension_impl.hpp 2008-07-08 12:48:36 EDT (Tue, 08 Jul 2008)
@@ -16,7 +16,6 @@
#include <boost/mpl/if.hpp>
#include <boost/mpl/list.hpp>
#include <boost/mpl/next.hpp>
-#include <boost/mpl/push_front.hpp>
#include <boost/mpl/size.hpp>
#include <boost/mpl/less.hpp>
@@ -37,118 +36,102 @@
namespace detail {
-template<bool second_is_less>
-struct sort_dims_conditional_swap;
+template<int N>
+struct insertion_sort_dims_insert;
+
+template<bool is_greater>
+struct insertion_sort_dims_comparison_impl;
+// have to recursively add the element to the next sequence.
template<>
-struct sort_dims_conditional_swap<true>
-{
- template<class T0, class T1>
- struct apply
- {
- typedef T1 first;
- typedef T0 second;
+struct insertion_sort_dims_comparison_impl<true> {
+ template<class Begin, int N, class T>
+ struct apply {
+ typedef list<
+ typename Begin::item,
+ typename insertion_sort_dims_insert<N - 1>::template apply<
+ typename Begin::next,
+ T
+ >::type
+ > type;
};
};
+// either prepend the current element or join it to
+// the first remaining element of the sequence.
template<>
-struct sort_dims_conditional_swap<false>
-{
- template<class T0, class T1>
- struct apply
- {
- typedef T0 first;
- typedef T1 second;
+struct insertion_sort_dims_comparison_impl<false> {
+ template<class Begin, int N, class T>
+ struct apply {
+ typedef typename push_front_or_add<Begin, T>::type type;
};
};
template<int N>
-struct sort_dims_pass_impl
-{
- template<class Begin, class Current>
- struct apply
- {
- typedef typename mpl::deref<Begin>::type val;
- typedef typename sort_dims_conditional_swap<mpl::less<val, Current>::value>::template apply<Current, val> pair;
- typedef typename sort_dims_pass_impl<N-1>::template apply<typename mpl::next<Begin>::type, typename pair::second> next;
- typedef typename push_front_or_add<typename next::type, typename pair::first>::type type;
- enum { value = next::value || mpl::less<val, Current>::value };
+struct insertion_sort_dims_insert {
+ template<class Begin, class T>
+ struct apply {
+ typedef typename insertion_sort_dims_comparison_impl<mpl::less<typename Begin::item, T>::value>::template apply<
+ Begin,
+ N,
+ T
+ >::type type;
};
};
template<>
-struct sort_dims_pass_impl<0>
-{
- template<class Begin, class Current>
- struct apply
- {
- typedef typename mpl::push_front<dimensionless_type, Current>::type type;
- enum { value = false };
+struct insertion_sort_dims_insert<0> {
+ template<class Begin, class T>
+ struct apply {
+ typedef list<T, dimensionless_type> type;
};
};
-template<bool>
-struct sort_dims_impl;
-
-template<>
-struct sort_dims_impl<true>
-{
- template<class T>
- struct apply
- {
- typedef typename mpl::begin<T>::type begin;
- typedef typename sort_dims_pass_impl<mpl::size<T>::value - 1>::template apply<
- typename mpl::next<begin>::type,
- typename mpl::deref<begin>::type
- > single_pass;
- typedef typename sort_dims_impl<(single_pass::value)>::template apply<typename single_pass::type>::type type;
+template<int N>
+struct insertion_sort_dims_mpl_sequence {
+ template<class Begin>
+ struct apply {
+ typedef typename insertion_sort_dims_mpl_sequence<N - 1>::template apply<typename mpl::next<Begin>::type>::type next;
+ typedef typename insertion_sort_dims_insert<(next::size::value)>::template apply<next, typename mpl::deref<Begin>::type>::type type;
};
};
template<>
-struct sort_dims_impl<false>
-{
- template<class T>
- struct apply
- {
- typedef T type;
+struct insertion_sort_dims_mpl_sequence<0> {
+ template<class Begin>
+ struct apply {
+ typedef dimensionless_type type;
};
};
template<int N>
-struct sort_dims_one_or_zero
-{
- template<class T>
- struct apply
- {
- typedef typename sort_dims_impl<true>::template apply<T>::type type;
+struct insertion_sort_dims_impl {
+ template<class Begin>
+ struct apply {
+ typedef typename insertion_sort_dims_impl<N - 1>::template apply<typename Begin::next>::type next;
+ typedef typename insertion_sort_dims_insert<(next::size::value)>::template apply<next, typename Begin::item>::type type;
};
};
template<>
-struct sort_dims_one_or_zero<0>
-{
- template<class T>
- struct apply
- {
+struct insertion_sort_dims_impl<0> {
+ template<class Begin>
+ struct apply {
typedef dimensionless_type type;
};
};
-template<>
-struct sort_dims_one_or_zero<1>
+template<class T>
+struct sort_dims
{
- template<class T>
- struct apply
- {
- typedef typename mpl::push_front<dimensionless_type, typename mpl::front<T>::type>::type type;
- };
+ typedef typename insertion_sort_dims_mpl_sequence<mpl::size<T>::value>::template apply<typename mpl::begin<T>::type>::type type;
};
-template<class T>
-struct sort_dims
+
+template<class T, class Next>
+struct sort_dims<list<T, Next> >
{
- typedef typename sort_dims_one_or_zero<mpl::size<T>::value>::template apply<T>::type type;
+ typedef typename insertion_sort_dims_impl<list<T, Next>::size::value>::template apply<list<T, Next> >::type type;
};
/// sorted sequences can be merged in linear time
@@ -164,13 +147,13 @@
template<typename Begin1, typename Begin2, int N1, int N2>
struct apply
{
- typedef typename mpl::push_front<
+ typedef list<
+ typename Begin1::item,
typename merge_dimensions_impl<N1 - 1, N2>::template apply<
- typename boost::mpl::next<Begin1>::type,
+ typename Begin1::next,
Begin2
- >::type,
- typename boost::mpl::deref<Begin1>::type
- >::type type;
+ >::type
+ > type;
};
};
@@ -179,13 +162,13 @@
template<typename Begin1, typename Begin2, int N1, int N2>
struct apply
{
- typedef typename mpl::push_front<
+ typedef list<
+ typename Begin2::item,
typename merge_dimensions_impl<N2 - 1, N1>::template apply<
- typename boost::mpl::next<Begin2>::type,
+ typename Begin2::next,
Begin1
- >::type,
- typename boost::mpl::deref<Begin2>::type
- >::type type;
+ >::type
+ > type;
};
};
@@ -194,11 +177,11 @@
template<typename Begin1, typename Begin2, int N1, int N2>
struct apply
{
- typedef typename mpl::plus<typename boost::mpl::deref<Begin1>::type, typename boost::mpl::deref<Begin2>::type>::type combined;
+ typedef typename mpl::plus<typename Begin1::item, typename Begin2::item>::type combined;
typedef typename push_front_if<!is_empty_dim<combined>::value>::template apply<
typename merge_dimensions_impl<N1 - 1, N2 - 1>::template apply<
- typename boost::mpl::next<Begin1>::type,
- typename boost::mpl::next<Begin2>::type
+ typename Begin1::next,
+ typename Begin2::next
>::type,
combined
>::type type;
@@ -210,8 +193,8 @@
template<typename Begin1, typename Begin2>
struct apply
{
- typedef typename boost::mpl::deref<Begin1>::type dim1;
- typedef typename boost::mpl::deref<Begin2>::type dim2;
+ typedef typename Begin1::item dim1;
+ typedef typename Begin2::item dim2;
typedef typename merge_dimensions_func<(mpl::less<dim1,dim2>::value == true),
(mpl::less<dim2,dim1>::value == true)>::template apply<
@@ -226,11 +209,11 @@
template<typename Sequence1, typename Sequence2>
struct merge_dimensions
{
- typedef typename detail::merge_dimensions_impl<boost::mpl::size<Sequence1>::value,
- boost::mpl::size<Sequence2>::value>::template
+ typedef typename detail::merge_dimensions_impl<Sequence1::size::value,
+ Sequence2::size::value>::template
apply<
- typename boost::mpl::begin<Sequence1>::type,
- typename boost::mpl::begin<Sequence2>::type
+ Sequence1,
+ Sequence2
>::type type;
};
@@ -240,12 +223,12 @@
template<typename Begin>
struct apply
{
- typedef typename mpl::push_front<
+ typedef list<
+ typename Begin::item,
typename iterator_to_list<N - 1>::template apply<
- typename boost::mpl::next<Begin>::type
- >::type,
- typename boost::mpl::deref<Begin>::type
- >::type type;
+ typename Begin::next
+ >::type
+ > type;
};
};
@@ -293,12 +276,12 @@
{
template<typename Begin>
struct apply {
- typedef typename boost::mpl::push_front<
+ typedef list<
+ typename mpl::negate<typename Begin::item>::type,
typename static_inverse_impl<N - 1>::template apply<
- typename boost::mpl::next<Begin>::type
- >::type,
- typename mpl::negate<typename boost::mpl::deref<Begin>::type>::type
- >::type type;
+ typename Begin::next
+ >::type
+ > type;
};
};
@@ -318,10 +301,10 @@
template<typename Begin, typename Ex>
struct apply
{
- typedef typename mpl::push_front<
- typename detail::static_power_impl<N - 1>::template apply<typename mpl::next<Begin>::type, Ex>::type,
- typename mpl::times<typename mpl::deref<Begin>::type, Ex>::type
- >::type type;
+ typedef list<
+ typename mpl::times<typename Begin::item, Ex>::type,
+ typename detail::static_power_impl<N - 1>::template apply<typename Begin::next, Ex>::type
+ > type;
};
};
@@ -339,10 +322,10 @@
struct static_root_impl {
template<class Begin, class Ex>
struct apply {
- typedef typename mpl::push_front<
- typename detail::static_root_impl<N - 1>::template apply<typename mpl::next<Begin>::type, Ex>::type,
- typename mpl::divides<typename mpl::deref<Begin>::type, Ex>::type
- >::type type;
+ typedef list<
+ typename mpl::divides<typename Begin::item, Ex>::type,
+ typename detail::static_root_impl<N - 1>::template apply<typename Begin::next, Ex>::type
+ > type;
};
};
Modified: branches/release/boost/units/detail/heterogeneous_conversion.hpp
==============================================================================
--- branches/release/boost/units/detail/heterogeneous_conversion.hpp (original)
+++ branches/release/boost/units/detail/heterogeneous_conversion.hpp 2008-07-08 12:48:36 EDT (Tue, 08 Jul 2008)
@@ -11,14 +11,8 @@
#ifndef BOOST_UNITS_DETAIL_HETEROGENEOUS_CONVERSION_HPP
#define BOOST_UNITS_DETAIL_HETEROGENEOUS_CONVERSION_HPP
-#include <boost/mpl/list/list0.hpp>
-#include <boost/mpl/next.hpp>
-#include <boost/mpl/deref.hpp>
-#include <boost/mpl/size.hpp>
-#include <boost/mpl/begin.hpp>
-#include <boost/mpl/push_front.hpp>
-
-#include <boost/mpl/print.hpp>
+#include <boost/mpl/minus.hpp>
+#include <boost/mpl/times.hpp>
#include <boost/units/static_rational.hpp>
#include <boost/units/homogeneous_system.hpp>
@@ -33,7 +27,7 @@
struct solve_end {
template<class Begin, class Y>
struct apply {
- typedef mpl::list0<> type;
+ typedef dimensionless_type type;
};
};
@@ -43,14 +37,14 @@
struct solve_normal {
template<class Begin, class Y>
struct apply {
- typedef typename mpl::next<Begin>::type next;
- typedef typename mpl::push_front<
- typename Next::template apply<next, Y>::type,
+ typedef typename Begin::next next;
+ typedef list<
typename mpl::minus<
typename mpl::times<X1, Y>::type,
- typename mpl::times<X2, typename mpl::deref<Begin>::type>::type
- >::type
- >::type type;
+ typename mpl::times<X2, typename Begin::item>::type
+ >::type,
+ typename Next::template apply<next, Y>::type
+ > type;
};
};
@@ -58,10 +52,10 @@
struct solve_leading_zeroes {
template<class Begin>
struct apply {
- typedef typename mpl::push_front<
- typename Next::template apply<typename mpl::next<Begin>::type>::type,
- typename mpl::deref<Begin>::type
- >::type type;
+ typedef list<
+ typename Begin::item,
+ typename Next::template apply<typename Begin::next>::type
+ > type;
};
typedef solve_leading_zeroes type;
};
@@ -76,8 +70,8 @@
template<class Begin>
struct apply {
typedef typename Next::template apply<
- typename mpl::next<Begin>::type,
- typename mpl::deref<Begin>::type
+ typename Begin::next,
+ typename Begin::item
>::type type;
};
};
@@ -86,10 +80,10 @@
struct solve_internal_zero {
template<class Begin, class Y>
struct apply {
- typedef typename mpl::push_front<
- typename Next::template apply<typename mpl::next<Begin>::type, Y>::type,
- typename mpl::deref<Begin>::type
- >::type type;
+ typedef list<
+ typename Begin::item,
+ typename Next::template apply<typename Begin::next, Y>::type
+ > type;
};
};
@@ -114,9 +108,9 @@
template<class Begin, class X>
struct apply {
typedef typename make_solve_list_internal_zero<
- typename mpl::deref<Begin>::type
+ typename Begin::item
>::template apply<
- typename make_solve_list_normal<N-1>::template apply<typename mpl::next<Begin>::type, X>::type,
+ typename make_solve_list_normal<N-1>::template apply<typename Begin::next, X>::type,
X
>::type type;
};
@@ -139,8 +133,8 @@
struct apply {
typedef solve_first_non_zero<
typename make_solve_list_normal<N-1>::template apply<
- typename mpl::next<Begin>::type,
- typename mpl::deref<Begin>::type
+ typename Begin::next,
+ typename Begin::item
>::type
> type;
};
@@ -152,7 +146,7 @@
struct apply {
typedef typename solve_leading_zeroes<
typename make_solve_list_leading_zeroes<N-1>::template apply<
- typename mpl::next<Begin>::type
+ typename Begin::next
>::type
>::type type;
};
@@ -162,7 +156,7 @@
struct make_solve_list_leading_zeroes {
template<class Begin>
struct apply {
- typedef typename make_solve_list_first_non_zero<typename mpl::deref<Begin>::type>::template apply<Begin, N>::type type;
+ typedef typename make_solve_list_first_non_zero<typename Begin::item>::template apply<Begin, N>::type type;
};
};
@@ -178,9 +172,9 @@
struct try_add_unit_impl {
template<class Begin, class L>
struct apply {
- typedef typename try_add_unit_impl<N-1>::template apply<typename mpl::next<Begin>::type, L>::type next;
- typedef typename mpl::deref<Begin>::type::template apply<typename mpl::begin<next>::type>::type type;
- BOOST_STATIC_ASSERT((mpl::size<next>::value - 1 == mpl::size<type>::value));
+ typedef typename try_add_unit_impl<N-1>::template apply<typename Begin::next, L>::type next;
+ typedef typename Begin::item::template apply<next>::type type;
+ BOOST_STATIC_ASSERT((next::size::value - 1 == type::size::value));
};
};
@@ -203,9 +197,9 @@
template<class Begin, class Current, class Units, class Dimensions, int N>
struct apply {
typedef typename make_homogeneous_system_impl<N-1>::template apply<
- typename mpl::next<Begin>::type,
- typename mpl::push_front<Current, T>::type,
- typename mpl::push_front<Units, typename mpl::deref<Begin>::type>::type,
+ typename Begin::next,
+ list<T, Current>,
+ list<typename Begin::item, Units>,
Dimensions
>::type type;
};
@@ -215,7 +209,7 @@
struct make_homogeneous_system_func<T, true> {
template<class Begin, class Current, class Units, class Dimensions, int N>
struct apply {
- typedef typename mpl::push_front<Units, typename mpl::deref<Begin>::type>::type type;
+ typedef list<typename Begin::item, Units> type;
};
};
@@ -224,7 +218,7 @@
template<class Begin, class Current, class Units, class Dimensions, int N>
struct apply {
typedef typename make_homogeneous_system_impl<N-1>::template apply<
- typename mpl::next<Begin>::type,
+ typename Begin::next,
Current,
Units,
Dimensions
@@ -237,7 +231,7 @@
template<class Begin, class Current, class Units, class Dimensions, int N>
struct apply {
typedef typename make_homogeneous_system_impl<N-1>::template apply<
- typename mpl::next<Begin>::type,
+ typename Begin::next,
Current,
Units,
Dimensions
@@ -249,15 +243,15 @@
struct make_homogeneous_system_impl {
template<class Begin, class Current, class Units, class Dimensions>
struct apply {
- typedef typename expand_dimensions<mpl::size<Dimensions>::value>::template apply<
- typename mpl::begin<Dimensions>::type,
- typename mpl::begin<typename mpl::deref<Begin>::type::dimension_type>::type
+ typedef typename expand_dimensions<Dimensions::size::value>::template apply<
+ Dimensions,
+ typename Begin::item::dimension_type
>::type dimensions;
- typedef typename try_add_unit_impl<mpl::size<Current>::value>::template apply<typename mpl::begin<Current>::type, dimensions>::type new_element;
- typedef typename make_solve_list_leading_zeroes<mpl::size<new_element>::value>::template apply<typename mpl::begin<new_element>::type>::type new_func;
+ typedef typename try_add_unit_impl<Current::size::value>::template apply<Current, dimensions>::type new_element;
+ typedef typename make_solve_list_leading_zeroes<new_element::size::value>::template apply<new_element>::type new_func;
typedef typename make_homogeneous_system_func<
new_func,
- ((mpl::size<Current>::value)+1) == (mpl::size<Dimensions>::value)
+ ((Current::size::value)+1) == (Dimensions::size::value)
>::template apply<Begin, Current, Units, Dimensions, N>::type type;
};
};
@@ -274,13 +268,13 @@
struct make_homogeneous_system {
typedef typename find_base_dimensions<Units>::type base_dimensions;
typedef homogeneous_system<
- typename bubble_sort<
+ typename insertion_sort<
typename make_homogeneous_system_impl<
- mpl::size<Units>::value
+ Units::size::value
>::template apply<
- typename mpl::begin<Units>::type,
- mpl::list0<>,
- mpl::list0<>,
+ Units,
+ dimensionless_type,
+ dimensionless_type,
base_dimensions
>::type
>::type
@@ -291,10 +285,10 @@
struct extract_base_units {
template<class Begin, class T>
struct apply {
- typedef typename mpl::push_front<
- typename extract_base_units<N-1>::template apply<typename mpl::next<Begin>::type, T>::type,
- typename mpl::deref<Begin>::type::tag_type
- >::type type;
+ typedef list<
+ typename Begin::item::tag_type,
+ typename extract_base_units<N-1>::template apply<typename Begin::next, T>::type
+ > type;
};
};
Modified: branches/release/boost/units/detail/linear_algebra.hpp
==============================================================================
--- branches/release/boost/units/detail/linear_algebra.hpp (original)
+++ branches/release/boost/units/detail/linear_algebra.hpp 2008-07-08 12:48:36 EDT (Tue, 08 Jul 2008)
@@ -12,22 +12,8 @@
#define BOOST_UNITS_DETAIL_LINEAR_ALGEBRA_HPP
#include <boost/units/static_rational.hpp>
-#include <boost/mpl/list.hpp>
-#include <boost/mpl/push_front.hpp>
-#include <boost/mpl/pop_front.hpp>
-#include <boost/mpl/deref.hpp>
-#include <boost/mpl/begin.hpp>
-#include <boost/mpl/size.hpp>
#include <boost/mpl/next.hpp>
#include <boost/mpl/arithmetic.hpp>
-#include <boost/mpl/front_inserter.hpp>
-#include <boost/mpl/set.hpp>
-#include <boost/mpl/insert.hpp>
-#include <boost/mpl/greater.hpp>
-#include <boost/mpl/reverse.hpp>
-#include <boost/mpl/advance.hpp>
-#include <boost/mpl/erase.hpp>
-#include <boost/mpl/front.hpp>
#include <boost/mpl/and.hpp>
#include <boost/mpl/assert.hpp>
@@ -77,6 +63,24 @@
struct inconsistent {};
+// generally useful utilies.
+
+template<int N>
+struct divide_equation {
+ template<class Begin, class Divisor>
+ struct apply {
+ typedef list<typename mpl::divides<typename Begin::item, Divisor>::type, typename divide_equation<N - 1>::template apply<typename Begin::next, Divisor>::type> type;
+ };
+};
+
+template<>
+struct divide_equation<0> {
+ template<class Begin, class Divisor>
+ struct apply {
+ typedef dimensionless_type type;
+ };
+};
+
// eliminate_from_pair_of_equations takes a pair of
// equations and eliminates the first variable.
//
@@ -90,18 +94,18 @@
struct eliminate_from_pair_of_equations_impl {
template<class Begin1, class Begin2, class X1, class X2>
struct apply {
- typedef typename mpl::push_front<
+ typedef list<
+ typename mpl::minus<
+ typename mpl::times<typename Begin1::item, X2>::type,
+ typename mpl::times<typename Begin2::item, X1>::type
+ >::type,
typename eliminate_from_pair_of_equations_impl<N - 1>::template apply<
- typename mpl::next<Begin1>::type,
- typename mpl::next<Begin2>::type,
+ typename Begin1::next,
+ typename Begin2::next,
X1,
X2
- >::type,
- typename mpl::minus<
- typename mpl::times<typename mpl::deref<Begin1>::type, X2>::type,
- typename mpl::times<typename mpl::deref<Begin2>::type, X1>::type
>::type
- >::type type;
+ > type;
};
};
@@ -109,295 +113,436 @@
struct eliminate_from_pair_of_equations_impl<0> {
template<class Begin1, class Begin2, class X1, class X2>
struct apply {
- typedef mpl::list0<> type;
+ typedef dimensionless_type type;
};
};
template<class E1, class E2>
struct eliminate_from_pair_of_equations {
- typedef typename mpl::begin<E1>::type begin1;
- typedef typename mpl::begin<E2>::type begin2;
- typedef typename eliminate_from_pair_of_equations_impl<mpl::size<E1>::value - 1>::template apply<
- typename mpl::next<begin1>::type,
- typename mpl::next<begin2>::type,
- typename mpl::deref<begin1>::type,
- typename mpl::deref<begin2>::type
+ typedef E1 begin1;
+ typedef E2 begin2;
+ typedef typename eliminate_from_pair_of_equations_impl<(E1::size::value - 1)>::template apply<
+ typename begin1::next,
+ typename begin2::next,
+ typename begin1::item,
+ typename begin2::item
>::type type;
};
-// Eliminates the first variable from a list of equations
-// returns inconsistent if all its coefficients are 0. Otherwise
-// recursively calls solve to find the remaining variables
-//
-// list<rational> eliminate(list<equation> system) {
-// list<equation> result;
-// equation eliminate_against = null;
-// for_each(equation e : system) {
-// if(eliminate_against == null) {
-// if(e.front() == 0) {
-// result = push_front(result, pop_front(e));
-// } else {
-// eliminate_against = e;
-// }
-// } else {
-// result = push_back(result, eliminate_from_pair_of_equations(e,eliminate_against));
-// }
-// }
-// if(eliminate_against == null) {
-// return(inconsistent);
-// } else {
-// list<rational> solution = solve(result);
-// return(push_front(solution, substitute(eliminate_against,solution)));
-// }
-// }
+
+
+// Stage 1. Determine which dimensions should
+// have dummy base units. For this purpose
+// row reduce the matrix.
template<int N>
-struct elimination_impl {
- template<class Begin, class Prev, class L>
+struct make_zero_vector {
+ typedef list<static_rational<0>, typename make_zero_vector<N - 1>::type> type;
+};
+template<>
+struct make_zero_vector<0> {
+ typedef dimensionless_type type;
+};
+
+template<int Column, int TotalColumns>
+struct create_row_of_identity {
+ typedef list<static_rational<0>, typename create_row_of_identity<Column - 1, TotalColumns - 1>::type> type;
+};
+template<int TotalColumns>
+struct create_row_of_identity<0, TotalColumns> {
+ typedef list<static_rational<1>, typename make_zero_vector<TotalColumns - 1>::type> type;
+};
+template<int Column>
+struct create_row_of_identity<Column, 0> {
+ // error
+};
+
+template<int RemainingRows>
+struct determine_extra_equations_impl;
+
+template<bool first_is_zero, bool is_last>
+struct determine_extra_equations_skip_zeros_impl;
+
+// not the last row and not zero.
+template<>
+struct determine_extra_equations_skip_zeros_impl<false, false> {
+ template<class RowsBegin, int RemainingRows, int CurrentColumn, int TotalColumns, class Result>
struct apply {
- typedef typename mpl::push_front<
- typename elimination_impl<N-1>::template apply<typename mpl::next<Begin>::type, Prev, L>::type,
- typename eliminate_from_pair_of_equations<typename mpl::deref<Begin>::type,Prev>::type
- >::type type;
+ // remove the equation being eliminated against from the set of equations.
+ typedef typename determine_extra_equations_impl<RemainingRows - 1>::template apply<typename RowsBegin::next, typename RowsBegin::item>::type next_equations;
+ // since this column was present, strip it out.
+ typedef Result type;
};
};
+// the last row but not zero.
template<>
-struct elimination_impl<0> {
- template<class Begin, class Prev, class L>
+struct determine_extra_equations_skip_zeros_impl<false, true> {
+ template<class RowsBegin, int RemainingRows, int CurrentColumn, int TotalColumns, class Result>
struct apply {
- typedef L type;
+ // remove this equation.
+ typedef dimensionless_type next_equations;
+ // since this column was present, strip it out.
+ typedef Result type;
};
};
+
+// the first columns is zero but it is not the last column.
+// continue with the same loop.
template<>
-struct elimination_skip_leading_zeros_impl<true, true> {
- template<class Begin, int N, class L>
+struct determine_extra_equations_skip_zeros_impl<true, false> {
+ template<class RowsBegin, int RemainingRows, int CurrentColumn, int TotalColumns, class Result>
struct apply {
- typedef inconsistent type;
+ typedef typename RowsBegin::item current_row;
+ typedef typename determine_extra_equations_skip_zeros_impl<
+ current_row::item::Numerator == 0,
+ RemainingRows == 2 // the next one will be the last.
+ >::template apply<
+ typename RowsBegin::next,
+ RemainingRows - 1,
+ CurrentColumn,
+ TotalColumns,
+ Result
+ > next;
+ typedef list<typename RowsBegin::item::next, typename next::next_equations> next_equations;
+ typedef typename next::type type;
};
};
+// all the elements in this column are zero.
template<>
-struct elimination_skip_leading_zeros_impl<true, false> {
- template<class Begin, int N, class L>
+struct determine_extra_equations_skip_zeros_impl<true, true> {
+ template<class RowsBegin, int RemainingRows, int CurrentColumn, int TotalColumns, class MatrixWithFirstColumnStripped, class Result>
struct apply {
- typedef typename mpl::next<Begin>::type next;
- typedef typename elimination_skip_leading_zeros_impl<
- boost::is_same<
- typename mpl::deref<
- typename mpl::begin<typename mpl::deref<next>::type>::type
- >::type,
- static_rational<0>
- >::value,
- N == 2
- >::template apply<
- next,
- N-1,
- typename mpl::push_front<
- L,
- typename mpl::pop_front<typename mpl::deref<Begin>::type>::type
- >::type
- >::type type;
+ typedef list<typename RowsBegin::item::next, dimensionless_type> next_equations;
+ typedef list<typename create_row_of_identity<CurrentColumn, TotalColumns>::type, Result> type;
};
};
-template<class S>
-struct combine_solutions {
- template<class Iterator>
+template<int RemainingRows>
+struct determine_extra_equations_impl {
+ template<class RowsBegin, class EliminateAgainst>
struct apply {
- typedef typename substitute<typename mpl::deref<Iterator>::type, S>::type x;
- typedef typename mpl::push_front<S, x>::type type;
+ typedef list<
+ typename eliminate_from_pair_of_equations<typename RowsBegin::item, EliminateAgainst>::type,
+ typename determine_extra_equations_impl<RemainingRows-1>::template apply<typename RowsBegin::next, EliminateAgainst>::type
+ > type;
};
};
template<>
-struct combine_solutions<inconsistent> {
- template<class Iterator>
+struct determine_extra_equations_impl<0> {
+ template<class RowsBegin, class EliminateAgainst>
struct apply {
- typedef inconsistent type;
+ typedef dimensionless_type type;
};
};
-template<>
-struct elimination_skip_leading_zeros_impl<false, true> {
- template<class Begin, int N, class L>
+template<int RemainingColumns, bool is_done>
+struct determine_extra_equations {
+ template<class RowsBegin, int TotalColumns, class Result>
struct apply {
- typedef typename elimination_impl<N - 1>::template apply<
- typename mpl::next<Begin>::type,
- typename mpl::deref<Begin>::type,
- L
- >::type list_type;
- typedef typename solve<list_type>::type next;
- typedef typename combine_solutions<next>::template apply<Begin>::type type;
+ typedef typename RowsBegin::item top_row;
+ typedef typename determine_extra_equations_skip_zeros_impl<
+ top_row::item::Numerator == 0,
+ RowsBegin::item::size::value == 1
+ >::template apply<
+ RowsBegin,
+ RowsBegin::size::value,
+ TotalColumns - RemainingColumns,
+ TotalColumns,
+ Result
+ > column_info;
+ typedef typename determine_extra_equations<
+ RemainingColumns - 1,
+ column_info::next_equations::size::value == 0
+ >::template apply<
+ typename column_info::next_equations,
+ TotalColumns,
+ typename column_info::type
+ >::type type;
+ };
+};
+
+template<int RemainingColumns>
+struct determine_extra_equations<RemainingColumns, true> {
+ template<class RowsBegin, int TotalColumns, class Result>
+ struct apply {
+ typedef typename determine_extra_equations<RemainingColumns - 1, true>::template apply<
+ RowsBegin,
+ TotalColumns,
+ list<typename create_row_of_identity<TotalColumns - RemainingColumns, TotalColumns>::type, Result>
+ >::type type;
};
};
template<>
-struct elimination_skip_leading_zeros_impl<false, false> {
- template<class Begin, int N, class L>
+struct determine_extra_equations<0, true> {
+ template<class RowsBegin, int TotalColumns, class Result>
struct apply {
- typedef typename elimination_impl<N - 1>::template apply<
- typename mpl::next<Begin>::type,
- typename mpl::deref<Begin>::type,
- L
- >::type list_type;
- typedef typename solve<list_type>::type next;
- typedef typename combine_solutions<next>::template apply<Begin>::type type;
+ typedef Result type;
};
};
-// finds the vaue of the first variable given the
-// values of all the other variables.
-//
-// rational substitute(equation e, list<rational> solutions) {
-// rational value = e.back();
-// for_each(rational x : solutions, rational a : pop_front(pop_back(e))) {
-// value -= a * x;
-// }
-// return(e.front() / value);
-// }
+// Stage 2
+// invert the matrix using Gauss-Jordan elimination
+
+
+template<bool is_zero, bool is_last>
+struct invert_strip_leading_zeroes;
template<int N>
-struct substitute_impl {
- template<class Begin1, class Begin2>
+struct invert_handle_after_pivot_row;
+
+// When processing column N, none of the first N rows
+// can be the pivot column.
+template<int N>
+struct invert_handle_inital_rows {
+ template<class RowsBegin, class IdentityBegin>
struct apply {
- typedef typename mpl::minus<
- typename substitute_impl<N-1>::template apply<
- typename mpl::next<Begin1>::type,
- typename mpl::next<Begin2>::type
+ typedef typename invert_handle_inital_rows<N - 1>::template apply<
+ typename RowsBegin::next,
+ typename IdentityBegin::next
+ > next;
+ typedef typename RowsBegin::item current_row;
+ typedef typename IdentityBegin::item current_identity_row;
+ typedef typename next::pivot_row pivot_row;
+ typedef typename next::identity_pivot_row identity_pivot_row;
+ typedef list<
+ typename eliminate_from_pair_of_equations_impl<(current_row::size::value) - 1>::template apply<
+ typename current_row::next,
+ pivot_row,
+ typename current_row::item,
+ static_rational<1>
>::type,
- typename mpl::times<
- typename mpl::deref<Begin1>::type,
- typename mpl::deref<Begin2>::type
- >::type
- >::type type;
+ typename next::new_matrix
+ > new_matrix;
+ typedef list<
+ typename eliminate_from_pair_of_equations_impl<(current_identity_row::size::value)>::template apply<
+ current_identity_row,
+ identity_pivot_row,
+ typename current_row::item,
+ static_rational<1>
+ >::type,
+ typename next::identity_result
+ > identity_result;
};
};
+// This handles the switch to searching for a pivot column.
+// The pivot row will be propagated up in the typedefs
+// pivot_row and identity_pivot_row. It is inserted here.
template<>
-struct substitute_impl<0> {
- template<class Begin1, class Begin2>
+struct invert_handle_inital_rows<0> {
+ template<class RowsBegin, class IdentityBegin>
struct apply {
- typedef typename mpl::deref<Begin1>::type type;
+ typedef typename RowsBegin::item current_row;
+ typedef typename invert_strip_leading_zeroes<
+ (current_row::item::Numerator == 0),
+ (RowsBegin::size::value == 1)
+ >::template apply<
+ RowsBegin,
+ IdentityBegin
+ > next;
+ // results
+ typedef list<typename next::pivot_row, typename next::new_matrix> new_matrix;
+ typedef list<typename next::identity_pivot_row, typename next::identity_result> identity_result;
+ typedef typename next::pivot_row pivot_row;
+ typedef typename next::identity_pivot_row identity_pivot_row;
};
};
-template<class Equation, class Vars>
-struct substitute {
- typedef typename mpl::begin<Equation>::type begin;
- typedef typename mpl::divides<
- typename substitute_impl<mpl::size<Vars>::value>::template apply<
- typename mpl::next<begin>::type,
- typename mpl::begin<Vars>::type
- >::type,
- typename mpl::deref<begin>::type
- >::type type;
+// The first internal element which is not zero.
+template<>
+struct invert_strip_leading_zeroes<false, false> {
+ template<class RowsBegin, class IdentityBegin>
+ struct apply {
+ typedef typename RowsBegin::item current_row;
+ typedef typename current_row::item current_value;
+ typedef typename divide_equation<(current_row::size::value - 1)>::template apply<typename current_row::next, current_value>::type new_equation;
+ typedef typename divide_equation<(IdentityBegin::item::size::value)>::template apply<typename IdentityBegin::item, current_value>::type transformed_identity_equation;
+ typedef typename invert_handle_after_pivot_row<(RowsBegin::size::value - 1)>::template apply<
+ typename RowsBegin::next,
+ typename IdentityBegin::next,
+ new_equation,
+ transformed_identity_equation
+ > next;
+
+ // results
+ // Note that we don't add the pivot row to the
+ // results here, because it needs to propagated up
+ // to the diagonal.
+ typedef typename next::new_matrix new_matrix;
+ typedef typename next::identity_result identity_result;
+ typedef new_equation pivot_row;
+ typedef transformed_identity_equation identity_pivot_row;
+ };
};
+// The one and only non-zero element--at the end
template<>
-struct solve_impl<true> {
- template<class T>
+struct invert_strip_leading_zeroes<false, true> {
+ template<class RowsBegin, class IdentityBegin>
struct apply {
- typedef mpl::list0<> type;
+ typedef typename RowsBegin::item current_row;
+ typedef typename current_row::item current_value;
+ typedef typename divide_equation<(current_row::size::value - 1)>::template apply<typename current_row::next, current_value>::type new_equation;
+ typedef typename divide_equation<(IdentityBegin::item::size::value)>::template apply<typename IdentityBegin::item, current_value>::type transformed_identity_equation;
+
+ // results
+ // Note that we don't add the pivot row to the
+ // results here, because it needs to propagated up
+ // to the diagonal.
+ typedef dimensionless_type identity_result;
+ typedef dimensionless_type new_matrix;
+ typedef new_equation pivot_row;
+ typedef transformed_identity_equation identity_pivot_row;
};
};
-// check_extra_equations verifies that the
-// after all the variables have been eliminated
-// the remaining equations are all 0=0.
-
-template<class T>
-struct check_extra_equations_func {
- template<class Begin, int N>
+// One of the initial zeroes
+template<>
+struct invert_strip_leading_zeroes<true, false> {
+ template<class RowsBegin, class IdentityBegin>
struct apply {
- typedef inconsistent type;
+ typedef typename RowsBegin::item current_row;
+ typedef typename RowsBegin::next::item next_row;
+ typedef typename invert_strip_leading_zeroes<
+ next_row::item::Numerator == 0,
+ RowsBegin::size::value == 2
+ >::template apply<
+ typename RowsBegin::next,
+ typename IdentityBegin::next
+ > next;
+ typedef typename IdentityBegin::item current_identity_row;
+ // these are propagated up.
+ typedef typename next::pivot_row pivot_row;
+ typedef typename next::identity_pivot_row identity_pivot_row;
+ typedef list<
+ typename eliminate_from_pair_of_equations_impl<(current_row::size::value - 1)>::template apply<
+ typename current_row::next,
+ pivot_row,
+ typename current_row::item,
+ static_rational<1>
+ >::type,
+ typename next::new_matrix
+ > new_matrix;
+ typedef list<
+ typename eliminate_from_pair_of_equations_impl<(current_identity_row::size::value)>::template apply<
+ current_identity_row,
+ identity_pivot_row,
+ typename current_row::item,
+ static_rational<1>
+ >::type,
+ typename next::identity_result
+ > identity_result;
};
};
+// the last element, and is zero.
+// Should never happen.
template<>
-struct check_extra_equations_func<static_rational<0> > {
- template<class Begin, int N>
- struct apply {
- typedef typename check_extra_equations_impl<N - 1>::template apply<typename mpl::next<Begin>::type>::type type;
- };
+struct invert_strip_leading_zeroes<true, true> {
};
template<int N>
-struct check_extra_equations_impl {
- template<class Begin>
+struct invert_handle_after_pivot_row {
+ template<class RowsBegin, class IdentityBegin, class MatrixPivot, class IdentityPivot>
struct apply {
- typedef typename check_extra_equations_func<
- typename mpl::deref<typename mpl::begin<typename mpl::deref<Begin>::type>::type>::type
- >::template apply<Begin, N>::type type;
+ typedef typename invert_handle_after_pivot_row<N - 1>::template apply<
+ typename RowsBegin::next,
+ typename IdentityBegin::next,
+ MatrixPivot,
+ IdentityPivot
+ > next;
+ typedef typename RowsBegin::item current_row;
+ typedef typename IdentityBegin::item current_identity_row;
+ typedef MatrixPivot pivot_row;
+ typedef IdentityPivot identity_pivot_row;
+
+ // results
+ typedef list<
+ typename eliminate_from_pair_of_equations_impl<(current_row::size::value - 1)>::template apply<
+ typename current_row::next,
+ pivot_row,
+ typename current_row::item,
+ static_rational<1>
+ >::type,
+ typename next::new_matrix
+ > new_matrix;
+ typedef list<
+ typename eliminate_from_pair_of_equations_impl<(current_identity_row::size::value)>::template apply<
+ current_identity_row,
+ identity_pivot_row,
+ typename current_row::item,
+ static_rational<1>
+ >::type,
+ typename next::identity_result
+ > identity_result;
};
};
template<>
-struct check_extra_equations_impl<0> {
- template<class Begin>
+struct invert_handle_after_pivot_row<0> {
+ template<class RowsBegin, class IdentityBegin, class MatrixPivot, class IdentityPivot>
struct apply {
- typedef mpl::list0<> type;
+ typedef dimensionless_type new_matrix;
+ typedef dimensionless_type identity_result;
};
};
-template<bool is_end>
-struct check_extra_equations;
-
-template<>
-struct check_extra_equations<true> {
- template<class T>
+template<int N>
+struct invert_impl {
+ template<class RowsBegin, class IdentityBegin>
struct apply {
- typedef typename check_extra_equations_impl<mpl::size<T>::value>::template apply<
- typename mpl::begin<T>::type
+ typedef typename invert_handle_inital_rows<RowsBegin::size::value - N>::template apply<RowsBegin, IdentityBegin> process_column;
+ typedef typename invert_impl<N - 1>::template apply<
+ typename process_column::new_matrix,
+ typename process_column::identity_result
>::type type;
};
};
template<>
-struct check_extra_equations<false> {
- template<class T>
+struct invert_impl<0> {
+ template<class RowsBegin, class IdentityBegin>
struct apply {
- typedef typename mpl::begin<T>::type begin;
- typedef typename elimination_skip_leading_zeros_impl<
- boost::is_same<
- typename mpl::deref<
- typename mpl::begin<typename mpl::deref<begin>::type>::type
- >::type,
- static_rational<0>
- >::value,
- mpl::size<T>::value == 1
- >::template apply<
- begin,
- mpl::size<T>::value,
- mpl::list0<>
- >::type type;
+ typedef IdentityBegin type;
};
};
-template<>
-struct solve_impl<false> {
- template<class T>
+template<int N>
+struct make_identity {
+ template<int Size>
struct apply {
- typedef typename mpl::begin<T>::type begin;
- typedef typename check_extra_equations<
- mpl::size<typename mpl::deref<begin>::type>::value == 1
- >::template apply<
- T
- >::type type;
+ typedef list<typename create_row_of_identity<Size - N, Size>::type, typename make_identity<N - 1>::template apply<Size>::type> type;
};
};
-// solve takes a list of equations and returns the solutions
-// as a vector. Each equation is interpreted as a sequence
-// of coefficients with the last item being the value e.g.
-// list<1, 2, 3> is 1 * x0 + 2 * x1 = 3
+template<>
+struct make_identity<0> {
+ template<int Size>
+ struct apply {
+ typedef dimensionless_type type;
+ };
+};
-template<class T>
-struct solve {
- typedef typename solve_impl<mpl::size<T>::value == 0>::template apply<T>::type type;
+template<class Matrix>
+struct make_square_and_invert {
+ typedef typename Matrix::item top_row;
+ typedef typename determine_extra_equations<(top_row::size::value), false>::template apply<
+ Matrix, // RowsBegin
+ top_row::size::value, // TotalColumns
+ Matrix // Result
+ >::type invertible;
+ typedef typename invert_impl<invertible::size::value>::template apply<
+ invertible,
+ typename make_identity<invertible::size::value>::template apply<invertible::size::value>::type
+ >::type type;
};
+
// find_base_dimensions takes a list of
// base_units and returns a sorted list
// of all the base_dimensions they use.
@@ -412,16 +557,65 @@
// return(sort(dimensions, _1 > _2, front_inserter(list<base_dimension>())));
// }
+typedef char set_no;
+struct set_yes { set_no dummy[2]; };
+
+template<class T>
+struct wrap {};
+
+struct set_end {
+ static set_no lookup(...);
+ typedef mpl::long_<0> size;
+};
+
+template<class T, class Next>
+struct set : Next {
+ using Next::lookup;
+ static set_yes lookup(wrap<T>*);
+ typedef T item;
+ typedef Next next;
+ typedef typename mpl::next<typename Next::size>::type size;
+};
+
+template<bool has_key>
+struct set_insert;
+
+template<>
+struct set_insert<true> {
+ template<class Set, class T>
+ struct apply {
+ typedef Set type;
+ };
+};
+
+template<>
+struct set_insert<false> {
+ template<class Set, class T>
+ struct apply {
+ typedef set<T, Set> type;
+ };
+};
+
+template<class Set, class T>
+struct has_key {
+ static const long size = sizeof(Set::lookup((wrap<T>*)0));
+ static const bool value = (size == sizeof(set_yes));
+};
+
template<int N>
struct find_base_dimensions_impl_impl {
template<class Begin, class S>
struct apply {
- typedef typename mpl::insert<
- typename find_base_dimensions_impl_impl<N-1>::template apply<
- typename mpl::next<Begin>::type,
- S
- >::type,
- typename mpl::deref<Begin>::type::tag_type
+ typedef typename find_base_dimensions_impl_impl<N-1>::template apply<
+ typename Begin::next,
+ S
+ >::type next;
+
+ typedef typename set_insert<
+ (has_key<next, typename Begin::item::tag_type>::value)
+ >::template apply<
+ next,
+ typename Begin::item::tag_type
>::type type;
};
};
@@ -438,9 +632,9 @@
struct find_base_dimensions_impl {
template<class Begin>
struct apply {
- typedef typename find_base_dimensions_impl_impl<mpl::size<typename mpl::deref<Begin>::type::dimension_type>::value>::template apply<
- typename mpl::begin<typename mpl::deref<Begin>::type::dimension_type>::type,
- typename find_base_dimensions_impl<N-1>::template apply<typename mpl::next<Begin>::type>::type
+ typedef typename find_base_dimensions_impl_impl<(Begin::item::dimension_type::size::value)>::template apply<
+ typename Begin::item::dimension_type,
+ typename find_base_dimensions_impl<N-1>::template apply<typename Begin::next>::type
>::type type;
};
};
@@ -449,16 +643,16 @@
struct find_base_dimensions_impl<0> {
template<class Begin>
struct apply {
- typedef mpl::set0<> type;
+ typedef set_end type;
};
};
template<class T>
struct find_base_dimensions {
- typedef typename bubble_sort<
+ typedef typename insertion_sort<
typename find_base_dimensions_impl<
- mpl::size<T>::value
- >::template apply<typename mpl::begin<T>::type>::type
+ (T::size::value)
+ >::template apply<T>::type
>::type type;
};
@@ -480,8 +674,8 @@
struct calculate_base_dimension_coefficients_func<true> {
template<class T>
struct apply {
- typedef typename mpl::deref<T>::type::value_type type;
- typedef typename mpl::next<T>::type next;
+ typedef typename T::item::value_type type;
+ typedef typename T::next next;
};
};
@@ -504,7 +698,7 @@
struct apply :
boost::is_same<
Dim,
- typename mpl::deref<Iterator>::type::tag_type
+ typename Iterator::item::tag_type
> {};
};
@@ -519,19 +713,19 @@
template<class BaseUnitDimensions,class Dim,class T>
struct apply {
typedef typename calculate_base_dimension_coefficients_func<
- begins_with_dimension<typename mpl::deref<BaseUnitDimensions>::type>::template apply<
+ begins_with_dimension<typename BaseUnitDimensions::item>::template apply<
Dim
>::value
>::template apply<
- typename mpl::deref<BaseUnitDimensions>::type
+ typename BaseUnitDimensions::item
> result;
typedef typename calculate_base_dimension_coefficients_impl<N-1>::template apply<
- typename mpl::next<BaseUnitDimensions>::type,
+ typename BaseUnitDimensions::next,
Dim,
- typename mpl::push_front<T, typename result::type>::type
+ list<typename result::type, T>
> next_;
typedef typename next_::type type;
- typedef typename mpl::push_front<typename next_::next, typename result::next>::type next;
+ typedef list<typename result::next, typename next_::next> next;
};
};
@@ -540,87 +734,7 @@
template<class Begin, class BaseUnitDimensions, class T>
struct apply {
typedef T type;
- typedef mpl::list0<> next;
- };
-};
-
-// solve_for_base_dimension_impl computes the
-// coefficients of each unit for all the base_dimensions.
-// the inner lists are in reverse order.
-
-template<int N>
-struct get_equations_for_base_dimension_impl {
- template<class Begin, class Units>
- struct apply {
- typedef typename calculate_base_dimension_coefficients_impl<mpl::size<Units>::value>::template apply<
- typename mpl::begin<Units>::type,
- typename mpl::deref<Begin>::type,
- mpl::list0<>
- > x;
- typedef typename mpl::push_front<
- typename get_equations_for_base_dimension_impl<N-1>::template apply<
- typename mpl::next<Begin>::type,
- typename x::next
- >::type,
- typename x::type
- >::type type;
- };
-};
-
-template<>
-struct get_equations_for_base_dimension_impl<0> {
- template<class Begin, class Units>
- struct apply {
- typedef mpl::list0<> type;
- };
-};
-
-// get_dimension_iterators_impl takes a list of base_units
-// and returns a list of the begin iterators of their
-// dimensions
-
-template<int N>
-struct get_dimension_iterators_impl {
- template<class Begin>
- struct apply {
- typedef typename mpl::push_front<
- typename get_dimension_iterators_impl<N-1>::template apply<typename mpl::next<Begin>::type>::type,
- typename mpl::begin<typename mpl::deref<Begin>::type::dimension_type>::type
- >::type type;
- };
-};
-
-template<>
-struct get_dimension_iterators_impl<0> {
- template<class Begin>
- struct apply {
- typedef mpl::list0<> type;
- };
-};
-
-// prepare_equations takes the result of
-// solve_for_base_dimension_impl and an index.
-// it sets the equation at the index equal to
-// one and all the others to zero. In the process
-// it reverses the inner lists thus yielding
-// a matrix that can be passed to solve.
-
-template<int N>
-struct prepare_equations_impl {
- template<class Begin, int M>
- struct apply {
- typedef typename mpl::push_front<
- typename prepare_equations_impl<N-1>::template apply<typename mpl::next<Begin>::type, M - 1>::type,
- typename mpl::reverse<typename mpl::push_front<typename mpl::deref<Begin>::type, static_rational<(M == 0 ? 1 : 0)> >::type>::type
- >::type type;
- };
-};
-
-template<>
-struct prepare_equations_impl<0> {
- template<class Begin, int M>
- struct apply {
- typedef mpl::list0<> type;
+ typedef dimensionless_type next;
};
};
@@ -642,10 +756,10 @@
BOOST_MPL_ASSERT_MSG((N > 0), base_units_are_probably_not_linearly_independent, (void));
template<class T>
struct apply {
- typedef typename mpl::push_front<
- typename add_zeroes_impl<N-1>::template apply<T>::type,
- static_rational<0>
- >::type type;
+ typedef list<
+ static_rational<0>,
+ typename add_zeroes_impl<N-1>::template apply<T>::type
+ > type;
};
};
@@ -657,205 +771,6 @@
};
};
-// add_solutions takes a list of equations
-// for the extra dummy units and a list
-// of the values of all the regular units.
-// It find the coefficients of all the dummy
-// units and pushes them onto the begining
-// of the list in reverse order (since the
-// dummy equations are reversed).
-
-template<int N>
-struct add_solutions_impl {
- template<class Begin, class T, class Solution>
- struct apply {
- typedef typename add_solutions_impl<N-1>::template apply<
- typename mpl::next<Begin>::type,
- typename mpl::push_front<
- T,
- typename substitute_impl<mpl::size<Solution>::value>::template apply<
- typename mpl::begin<typename mpl::deref<Begin>::type>::type,
- typename mpl::begin<Solution>::type
- >::type
- >::type,
- Solution
- >::type type;
- };
-};
-
-template<>
-struct add_solutions_impl<0> {
- template<class Begin, class T, class Solution>
- struct apply {
- typedef T type;
- };
-};
-
-// normalize_units finds the units corresponding
-// to each base dimension. The form of the result is
-// a two dimensional list. list<list<rational> >.
-// each of the inner lists represents a single
-// base dimension. There may be extra units added
-// to the front of the inner list if there are
-// more base dimensions than base units. The
-// number such units is returned as a long called
-// extra. For example list<pound, foot> will yield
-// list<list<0, 0, 1>,list<1, 0, 0>,list<1/2,-1/2,1/2> > meaning
-//
-// length = 0 * mass + 0 * force + 1 * length
-// mass = 1 * mass + 0 * force + 0 * length
-// time = 1/2 * mass - 1/2 * force + 1/2 * length
-//
-// Why is there a dummy mass unit? It isn't
-// possible to represent three base dimensions
-// with only two base units. So we need some
-// kind of dummy. Why mass? Well, a base
-// unit of length doesn't help us since we
-// already have one. Mass is before time
-// so we use mass.
-
-// S is the solution for this particular base dimension.
-// if the base dimension cannot be represented then
-// solve will return inconsistent hence the two specializations.
-
-template<class S>
-struct normalize_units_func {
- template<class ReverseEquations, int M, class DimensionIterator, int N, int Extra, int I,class ExtraEquations>
- struct apply {
- // first add zeroes for all the extra units that
- // are not needed.
- typedef typename add_zeroes_impl<Extra-mpl::size<ExtraEquations>::value>::template apply<S>::type result1;
- // then find the values for the extra units that /are/ needed.
- typedef typename add_solutions_impl<mpl::size<ExtraEquations>::value>::template apply<
- typename mpl::begin<ExtraEquations>::type,
- result1,
- S
- >::type result;
- // recurse back to the primary loop putting
- // push_front outside since we wish to maintain
- // the original ordering of dimensions
- typedef typename mpl::push_front<
- typename normalize_units_impl<N-1>::template apply<
- // The coefficient are still the same
- // and we don't need to remove any equations
- ReverseEquations,
- // increment the number of equations that
- // need to be skipped when we add another
- // dummy unit.
- M+1,
- typename mpl::next<DimensionIterator>::type,
- Extra,
- // increment the number of dimensions we've seen
- I+1,
- // pass the equations for the dummy
- // units on without modification.
- ExtraEquations
- >::type,
- result
- >::type type;
- };
-};
-
-// handles the case when this base dimension
-// cannot be represented with the base units
-// and the dummies allready added.
-template<>
-struct normalize_units_func<inconsistent> {
- template<class ReverseEquations, int M, class DimensionIterator, int N, int Extra, int I, class ExtraEquations>
- struct apply {
- // Find the position that needs to be erased. (Since this
- // equation can always be adjusted by adjusting the
- // dummy unit we are adding now, independently of
- // other units, we don't need it anymore.)
- typedef typename mpl::advance_c<typename mpl::begin<ReverseEquations>::type, M>::type pos;
- // Continue with the main loop.
- typedef typename normalize_units_impl<N-1>::template apply<
- // Remove current_equation
- typename mpl::erase<
- ReverseEquations,
- pos
- >::type,
- M,
- typename mpl::next<DimensionIterator>::type,
- Extra,
- // Increment the number of dimensions we've seen
- I+1,
- // Add "current_equation == 0" to the list of equations
- // for the dummy units. (For all base dimensions
- // except this the current dimension must sum to
- // zero.)
- typename mpl::push_front<
- ExtraEquations,
- // Remember it's backwards
- typename mpl::reverse<
- typename mpl::push_front<typename mpl::deref<pos>::type, static_rational<0> >::type
- >::type
- >::type
- > next;
- // this dimension is (0, ..., 0, 1, 0, ..., 0)
- typedef typename mpl::push_front<
- typename add_zeroes_impl<N-1>::template apply<mpl::list0<> >::type,
- static_rational<1>
- >::type result1;
- typedef typename add_zeroes_impl<I>::template apply<result1>::type result;
- // Push the result onto the list.
- typedef typename mpl::push_front<typename next::type, result>::type type;
- };
-};
-
-template<int N>
-struct normalize_units_impl {
- template<class ReverseEquations, int M, class DimensionIterator, int Extra, int I, class ExtraEquations>
- struct apply {
- typedef typename solve<
- typename prepare_equations_impl<
- mpl::size<ReverseEquations>::value
- >::template apply<
- typename mpl::begin<ReverseEquations>::type,
- M
- >::type
- >::type solution;
- typedef typename normalize_units_func<solution>::template apply<
- ReverseEquations,
- M,
- DimensionIterator,
- N,
- Extra,
- I,
- ExtraEquations
- >::type type;
- };
-};
-
-template<>
-struct normalize_units_impl<0> {
- template<class ReverseEquations, int M, class DimensionIterator, int Extra, int I, class ExtraEquations>
- struct apply {
- typedef mpl::list0<> type;
- };
-};
-
-template<class T>
-struct normalize_units {
- typedef typename find_base_dimensions<T>::type dimensions;
- typedef typename get_dimension_iterators_impl<mpl::size<T>::value>::template apply<typename mpl::begin<T>::type>::type iterators;
- typedef typename get_equations_for_base_dimension_impl<
- mpl::size<dimensions>::value
- >::template apply<
- typename mpl::begin<dimensions>::type,
- iterators
- >::type reverse_equations;
- static const long extra = mpl::size<reverse_equations>::value - mpl::size<T>::value;
- typedef typename normalize_units_impl<mpl::size<reverse_equations>::value>::template apply<
- reverse_equations,
- 0,
- typename mpl::begin<dimensions>::type,
- extra,
- 0,
- mpl::list0<>
- >::type type;
-};
-
// expand_dimensions finds the exponents of
// a set of dimensions in a dimension_list.
// the second parameter is assumed to be
@@ -869,12 +784,12 @@
template<class Begin, class DimensionIterator>
struct apply {
typedef typename calculate_base_dimension_coefficients_func<
- begins_with_dimension<DimensionIterator>::template apply<typename mpl::deref<Begin>::type>::value
+ begins_with_dimension<DimensionIterator>::template apply<typename Begin::item>::value
>::template apply<DimensionIterator> result;
- typedef typename mpl::push_front<
- typename expand_dimensions<N-1>::template apply<typename mpl::next<Begin>::type, typename result::next>::type,
- typename result::type
- >::type type;
+ typedef list<
+ typename result::type,
+ typename expand_dimensions<N-1>::template apply<typename Begin::next, typename result::next>::type
+ > type;
};
};
@@ -882,10 +797,38 @@
struct expand_dimensions<0> {
template<class Begin, class DimensionIterator>
struct apply {
- typedef mpl::list0<> type;
+ typedef dimensionless_type type;
+ };
+};
+
+template<int N>
+struct create_unit_matrix {
+ template<class Begin, class Dimensions>
+ struct apply {
+ typedef typename create_unit_matrix<N - 1>::template apply<typename Begin::next, Dimensions>::type next;
+ typedef list<typename expand_dimensions<Dimensions::size::value>::template apply<Dimensions, typename Begin::item::dimension_type>::type, next> type;
};
};
+template<>
+struct create_unit_matrix<0> {
+ template<class Begin, class Dimensions>
+ struct apply {
+ typedef dimensionless_type type;
+ };
+};
+
+template<class T>
+struct normalize_units {
+ typedef typename find_base_dimensions<T>::type dimensions;
+ typedef typename create_unit_matrix<(T::size::value)>::template apply<
+ T,
+ dimensions
+ >::type matrix;
+ typedef typename make_square_and_invert<matrix>::type type;
+ static const long extra = (type::size::value) - (T::size::value);
+};
+
// multiply_add_units computes M x V
// where M is a matrix and V is a horizontal
// vector
@@ -896,20 +839,20 @@
struct multiply_add_units_impl {
template<class Begin1, class Begin2 ,class X>
struct apply {
- typedef typename mpl::push_front<
- typename multiply_add_units_impl<N-1>::template apply<
- typename mpl::next<Begin1>::type,
- typename mpl::next<Begin2>::type,
- X
- >::type,
+ typedef list<
typename mpl::plus<
typename mpl::times<
- typename mpl::deref<Begin2>::type,
+ typename Begin2::item,
X
>::type,
- typename mpl::deref<Begin1>::type
+ typename Begin1::item
+ >::type,
+ typename multiply_add_units_impl<N-1>::template apply<
+ typename Begin1::next,
+ typename Begin2::next,
+ X
>::type
- >::type type;
+ > type;
};
};
@@ -917,7 +860,7 @@
struct multiply_add_units_impl<0> {
template<class Begin1, class Begin2 ,class X>
struct apply {
- typedef mpl::list0<> type;
+ typedef dimensionless_type type;
};
};
@@ -926,16 +869,14 @@
template<class Begin1, class Begin2>
struct apply {
typedef typename multiply_add_units_impl<
- mpl::size<typename mpl::deref<Begin2>::type>::value
+ (Begin2::item::size::value)
>::template apply<
- typename mpl::begin<
- typename multiply_add_units<N-1>::template apply<
- typename mpl::next<Begin1>::type,
- typename mpl::next<Begin2>::type
- >::type
+ typename multiply_add_units<N-1>::template apply<
+ typename Begin1::next,
+ typename Begin2::next
>::type,
- typename mpl::begin<typename mpl::deref<Begin2>::type>::type,
- typename mpl::deref<Begin1>::type
+ typename Begin2::item,
+ typename Begin1::item
>::type type;
};
};
@@ -945,16 +886,14 @@
template<class Begin1, class Begin2>
struct apply {
typedef typename add_zeroes_impl<
- mpl::size<typename mpl::deref<Begin2>::type>::value
- >::template apply<mpl::list0<> >::type type1;
+ (Begin2::item::size::value)
+ >::template apply<dimensionless_type>::type type1;
typedef typename multiply_add_units_impl<
- mpl::size<typename mpl::deref<Begin2>::type>::value
+ (Begin2::item::size::value)
>::template apply<
- typename mpl::begin<
- type1
- >::type,
- typename mpl::begin<typename mpl::deref<Begin2>::type>::type,
- typename mpl::deref<Begin1>::type
+ type1,
+ typename Begin2::item,
+ typename Begin1::item
>::type type;
};
};
@@ -988,7 +927,7 @@
struct strip_zeroes_func<static_rational<0> > {
template<class L, int N>
struct apply {
- typedef typename strip_zeroes_impl<N-1>::template apply<typename mpl::pop_front<L>::type>::type type;
+ typedef typename strip_zeroes_impl<N-1>::template apply<typename L::next>::type type;
};
};
@@ -996,7 +935,7 @@
struct strip_zeroes_impl {
template<class T>
struct apply {
- typedef typename strip_zeroes_func<typename mpl::front<T>::type>::template apply<T, N>::type type;
+ typedef typename strip_zeroes_func<typename T::item>::template apply<T, N>::type type;
};
};
@@ -1043,12 +982,12 @@
struct is_simple_system_impl {
template<class Begin, class Prev>
struct apply {
- typedef is_base_dimension_unit<typename mpl::deref<Begin>::type::dimension_type> test;
+ typedef is_base_dimension_unit<typename Begin::item::dimension_type> test;
typedef mpl::and_<
typename test::type,
mpl::less<Prev, typename test::base_dimension_type>,
typename is_simple_system_impl<N-1>::template apply<
- typename mpl::next<Begin>::type,
+ typename Begin::next,
typename test::base_dimension_type
>
> type;
@@ -1065,14 +1004,14 @@
template<class T>
struct is_simple_system {
- typedef typename mpl::begin<T>::type Begin;
- typedef is_base_dimension_unit<typename mpl::deref<Begin>::type::dimension_type> test;
+ typedef T Begin;
+ typedef is_base_dimension_unit<typename Begin::item::dimension_type> test;
typedef typename mpl::and_<
typename test::type,
typename is_simple_system_impl<
- mpl::size<T>::value - 1
+ T::size::value - 1
>::template apply<
- typename mpl::next<Begin>::type,
+ typename Begin::next::type,
typename test::base_dimension_type
>
>::type type;
@@ -1086,9 +1025,9 @@
struct calculate_base_unit_exponents_impl<true> {
template<class T, class Dimensions>
struct apply {
- typedef typename expand_dimensions<mpl::size<T>::value>::template apply<
- typename mpl::begin<typename find_base_dimensions<T>::type>::type,
- typename mpl::begin<Dimensions>::type
+ typedef typename expand_dimensions<(T::size::value)>::template apply<
+ typename find_base_dimensions<T>::type,
+ Dimensions
>::type type;
};
};
@@ -1104,16 +1043,16 @@
// e.g. if the arguments are list<pound, foot> and
// list<mass,time^-2> then this step will
// yield list<0,1,-2>
- typedef typename expand_dimensions<mpl::size<typename base_solutions::dimensions>::value>::template apply<
- typename mpl::begin<typename base_solutions::dimensions>::type,
- typename mpl::begin<Dimensions>::type
+ typedef typename expand_dimensions<(base_solutions::dimensions::size::value)>::template apply<
+ typename base_solutions::dimensions,
+ Dimensions
>::type dimensions;
// take the unit corresponding to each base unit
// multiply each of its exponents by the exponent
// of the base_dimension in the result and sum.
- typedef typename multiply_add_units<mpl::size<dimensions>::value>::template apply<
- typename mpl::begin<dimensions>::type,
- typename mpl::begin<typename base_solutions::type>::type
+ typedef typename multiply_add_units<dimensions::size::value>::template apply<
+ dimensions,
+ typename base_solutions::type
>::type units;
// Now, verify that the dummy units really
// cancel out and remove them.
Modified: branches/release/boost/units/detail/push_front_if.hpp
==============================================================================
--- branches/release/boost/units/detail/push_front_if.hpp (original)
+++ branches/release/boost/units/detail/push_front_if.hpp 2008-07-08 12:48:36 EDT (Tue, 08 Jul 2008)
@@ -11,12 +11,13 @@
#ifndef BOOST_UNITS_DETAIL_PUSH_FRONT_IF_HPP
#define BOOST_UNITS_DETAIL_PUSH_FRONT_IF_HPP
-#include <boost/mpl/push_front.hpp>
-
namespace boost {
namespace units {
+template<class T, class Next>
+struct list;
+
namespace detail {
template<bool>
@@ -26,7 +27,7 @@
struct push_front_if<true> {
template<class L, class T>
struct apply {
- typedef typename mpl::push_front<L, T>::type type;
+ typedef list<T, L> type;
};
};
Modified: branches/release/boost/units/detail/push_front_or_add.hpp
==============================================================================
--- branches/release/boost/units/detail/push_front_or_add.hpp (original)
+++ branches/release/boost/units/detail/push_front_or_add.hpp 2008-07-08 12:48:36 EDT (Tue, 08 Jul 2008)
@@ -24,6 +24,9 @@
namespace units {
+template<class Item, class Next>
+struct list;
+
namespace detail {
template<class T>
@@ -39,9 +42,9 @@
template<typename Sequence, typename T>
struct apply
{
- typedef typename mpl::plus<T, typename mpl::front<Sequence>::type>::type item;
+ typedef typename mpl::plus<T, typename Sequence::item>::type item;
typedef typename push_front_if<!is_empty_dim<item>::value>::template apply<
- typename mpl::pop_front<Sequence>::type,
+ typename Sequence::next,
item
> type;
};
@@ -53,14 +56,14 @@
template<typename Sequence, typename T>
struct apply
{
- typedef typename mpl::push_front<Sequence, T>::type type;
+ typedef list<T, Sequence> type;
};
};
template<typename Sequence, typename T>
struct push_front_or_add
{
- typedef typename push_front_or_add_impl<boost::is_same<typename T::tag_type, typename mpl::front<Sequence>::type::tag_type>::value>::template apply<
+ typedef typename push_front_or_add_impl<boost::is_same<typename T::tag_type, typename Sequence::item::tag_type>::value>::template apply<
Sequence,
T
>::type type;
@@ -69,7 +72,7 @@
template<typename T>
struct push_front_or_add<dimensionless_type, T>
{
- typedef typename mpl::push_front<dimensionless_type, T>::type type;
+ typedef list<T, dimensionless_type> type;
};
} // namespace detail
Modified: branches/release/boost/units/detail/sort.hpp
==============================================================================
--- branches/release/boost/units/detail/sort.hpp (original)
+++ branches/release/boost/units/detail/sort.hpp 2008-07-08 12:48:36 EDT (Tue, 08 Jul 2008)
@@ -27,118 +27,77 @@
namespace detail {
-template<bool second_is_less>
-struct bubble_sort_conditional_swap;
+template<int N>
+struct insertion_sort_insert;
-template<>
-struct bubble_sort_conditional_swap<true>
-{
- template<class T0, class T1>
- struct apply
- {
- typedef T1 first;
- typedef T0 second;
- };
-};
+template<bool is_greater>
+struct insertion_sort_comparison_impl;
+// have to recursively add the element to the next sequence.
template<>
-struct bubble_sort_conditional_swap<false>
-{
- template<class T0, class T1>
- struct apply
- {
- typedef T0 first;
- typedef T1 second;
- };
-};
-
-template<int N>
-struct bubble_sort_pass_impl
-{
- template<class Begin, class Current>
- struct apply
- {
- typedef typename mpl::deref<Begin>::type val;
- typedef typename bubble_sort_conditional_swap<mpl::less<val, Current>::value>::template apply<Current, val> pair;
- typedef typename bubble_sort_pass_impl<N-1>::template apply<typename mpl::next<Begin>::type, typename pair::second> next;
- typedef typename mpl::push_front<typename next::type, typename pair::first>::type type;
- enum { value = next::value || mpl::less<val, Current>::value };
+struct insertion_sort_comparison_impl<true> {
+ template<class Begin, int N, class T>
+ struct apply {
+ typedef list<
+ typename Begin::item,
+ typename insertion_sort_insert<N - 1>::template apply<
+ typename Begin::next,
+ T
+ >::type
+ > type;
};
};
+// prepend the current element
template<>
-struct bubble_sort_pass_impl<0>
-{
- template<class Begin, class Current>
- struct apply
- {
- typedef typename mpl::push_front<dimensionless_type, Current>::type type;
- enum { value = false };
+struct insertion_sort_comparison_impl<false> {
+ template<class Begin, int N, class T>
+ struct apply {
+ typedef list<T, Begin> type;
};
};
-template<bool>
-struct bubble_sort_impl;
-
-template<>
-struct bubble_sort_impl<true>
-{
- template<class T>
- struct apply
- {
- typedef typename mpl::begin<T>::type begin;
- typedef typename bubble_sort_pass_impl<mpl::size<T>::value - 1>::template apply<
- typename mpl::next<begin>::type,
- typename mpl::deref<begin>::type
- > single_pass;
- typedef typename bubble_sort_impl<(single_pass::value)>::template apply<typename single_pass::type>::type type;
+template<int N>
+struct insertion_sort_insert {
+ template<class Begin, class T>
+ struct apply {
+ typedef typename insertion_sort_comparison_impl<mpl::less<typename Begin::item, T>::value>::template apply<
+ Begin,
+ N,
+ T
+ >::type type;
};
};
template<>
-struct bubble_sort_impl<false>
-{
- template<class T>
- struct apply
- {
- typedef T type;
+struct insertion_sort_insert<0> {
+ template<class Begin, class T>
+ struct apply {
+ typedef list<T, dimensionless_type> type;
};
};
template<int N>
-struct bubble_sort_one_or_zero
-{
- template<class T>
- struct apply
- {
- typedef typename bubble_sort_impl<true>::template apply<T>::type type;
+struct insertion_sort_impl {
+ template<class Begin>
+ struct apply {
+ typedef typename insertion_sort_impl<N - 1>::template apply<typename Begin::next>::type next;
+ typedef typename insertion_sort_insert<(next::size::value)>::template apply<next, typename Begin::item>::type type;
};
};
template<>
-struct bubble_sort_one_or_zero<0>
-{
- template<class T>
- struct apply
- {
+struct insertion_sort_impl<0> {
+ template<class Begin>
+ struct apply {
typedef dimensionless_type type;
};
};
-template<>
-struct bubble_sort_one_or_zero<1>
-{
- template<class T>
- struct apply
- {
- typedef typename mpl::push_front<dimensionless_type, typename mpl::front<T>::type>::type type;
- };
-};
-
template<class T>
-struct bubble_sort
+struct insertion_sort
{
- typedef typename bubble_sort_one_or_zero<mpl::size<T>::value>::template apply<T>::type type;
+ typedef typename insertion_sort_impl<T::size::value>::template apply<T>::type type;
};
} // namespace detail
Modified: branches/release/boost/units/detail/unscale.hpp
==============================================================================
--- branches/release/boost/units/detail/unscale.hpp (original)
+++ branches/release/boost/units/detail/unscale.hpp 2008-07-08 12:48:36 EDT (Tue, 08 Jul 2008)
@@ -141,11 +141,11 @@
template<class Begin>
struct apply
{
- typedef typename eval_scale_list_impl<N-1>::template apply<typename mpl::next<Begin>::type> next_iteration;
- typedef typename multiply_typeof_helper<typename next_iteration::type, typename mpl::deref<Begin>::type::value_type>::type type;
+ typedef typename eval_scale_list_impl<N-1>::template apply<typename Begin::next> next_iteration;
+ typedef typename multiply_typeof_helper<typename next_iteration::type, typename Begin::item::value_type>::type type;
static type value()
{
- return(next_iteration::value() * mpl::deref<Begin>::type::value());
+ return(next_iteration::value() * Begin::item::value());
}
};
};
@@ -168,7 +168,7 @@
/// INTERNAL ONLY
template<class T>
-struct eval_scale_list : detail::eval_scale_list_impl<mpl::size<T>::value>::template apply<typename mpl::begin<T>::type> {};
+struct eval_scale_list : detail::eval_scale_list_impl<T::size::value>::template apply<T> {};
} // namespace units
Modified: branches/release/boost/units/dimension.hpp
==============================================================================
--- branches/release/boost/units/dimension.hpp (original)
+++ branches/release/boost/units/dimension.hpp 2008-07-08 12:48:36 EDT (Tue, 08 Jul 2008)
@@ -16,8 +16,6 @@
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/arithmetic.hpp>
-#include <boost/mpl/begin.hpp>
-#include <boost/mpl/size.hpp>
#include <boost/units/static_rational.hpp>
#include <boost/units/detail/dimension_list.hpp>
@@ -62,8 +60,8 @@
template<typename DL,typename Ex>
struct static_power
{
- typedef typename detail::static_power_impl<mpl::size<DL>::value>::template apply<
- typename mpl::begin<DL>::type,
+ typedef typename detail::static_power_impl<DL::size::value>::template apply<
+ DL,
Ex
>::type type;
};
@@ -72,8 +70,8 @@
template<typename DL,typename Rt>
struct static_root
{
- typedef typename detail::static_root_impl<mpl::size<DL>::value>::template apply<
- typename mpl::begin<DL>::type,
+ typedef typename detail::static_root_impl<DL::size::value>::template apply<
+ DL,
Rt
>::type type;
};
@@ -125,9 +123,9 @@
typedef typename boost::units::detail::merge_dimensions<
T0,
typename boost::units::detail::static_inverse_impl<
- mpl::size<T1>::value
+ T1::size::value
>::template apply<
- typename mpl::begin<T1>::type
+ T1
>::type
>::type type;
};
Modified: branches/release/boost/units/heterogeneous_system.hpp
==============================================================================
--- branches/release/boost/units/heterogeneous_system.hpp (original)
+++ branches/release/boost/units/heterogeneous_system.hpp 2008-07-08 12:48:36 EDT (Tue, 08 Jul 2008)
@@ -214,12 +214,12 @@
template<class UnitsBegin, class ExponentsBegin>
struct apply
{
- typedef typename push_front_if<!(is_zero<typename mpl::deref<ExponentsBegin>::type>::value)>::template apply<
+ typedef typename push_front_if<!(is_zero<typename ExponentsBegin::item>::value)>::template apply<
typename make_heterogeneous_system_impl<N-1>::template apply<
- typename mpl::next<UnitsBegin>::type,
- typename mpl::next<ExponentsBegin>::type
+ typename UnitsBegin::next,
+ typename ExponentsBegin::next
>::type,
- heterogeneous_system_dim<typename mpl::deref<UnitsBegin>::type, typename mpl::deref<ExponentsBegin>::type>
+ heterogeneous_system_dim<typename UnitsBegin::item, typename ExponentsBegin::item>
>::type type;
};
};
@@ -239,9 +239,9 @@
{
typedef typename calculate_base_unit_exponents<typename System::type, Dimensions>::type exponents;
BOOST_MPL_ASSERT_MSG((!boost::is_same<exponents, inconsistent>::value), the_specified_dimension_is_not_representible_in_the_given_system, (types<Dimensions, System>));
- typedef typename make_heterogeneous_system_impl<mpl::size<typename System::type>::value>::template apply<
- typename mpl::begin<typename System::type>::type,
- typename mpl::begin<exponents>::type
+ typedef typename make_heterogeneous_system_impl<System::type::size::value>::template apply<
+ typename System::type,
+ exponents
>::type unit_list;
typedef heterogeneous_system<heterogeneous_system_impl<unit_list, Dimensions, no_scale> > type;
};
@@ -314,9 +314,9 @@
{
typedef typename push_front_or_add<
typename unscale_heterogeneous_system_impl<N-1>::template apply<
- typename mpl::next<Begin>::type
+ typename Begin::next
>::type,
- typename unscale<typename mpl::deref<Begin>::type>::type
+ typename unscale<typename Begin::item>::type
>::type type;
};
};
@@ -343,9 +343,9 @@
typedef heterogeneous_system<
heterogeneous_system_impl<
typename detail::unscale_heterogeneous_system_impl<
- mpl::size<typename T::type>::value
+ T::type::size::value
>::template apply<
- typename mpl::begin<typename T::type>::type
+ typename T::type
>::type,
typename T::dimensions,
no_scale
@@ -370,9 +370,9 @@
{
typedef typename mpl::times<
typename get_scale_list_of_heterogeneous_system_impl<N-1>::template apply<
- typename mpl::next<Begin>::type
+ typename Begin::next
>::type,
- typename get_scale_list<typename mpl::deref<Begin>::type>::type
+ typename get_scale_list<typename Begin::item>::type
>::type type;
};
};
@@ -395,7 +395,7 @@
{
typedef typename mpl::times<
typename detail::get_scale_list_of_heterogeneous_system_impl<
- mpl::size<typename T::type>::value
+ T::type::size::value
>::template apply<typename T::type>::type,
typename T::scale
>::type type;
Modified: branches/release/boost/units/io.hpp
==============================================================================
--- branches/release/boost/units/io.hpp (original)
+++ branches/release/boost/units/io.hpp 2008-07-08 12:48:36 EDT (Tue, 08 Jul 2008)
@@ -208,10 +208,10 @@
template<class Begin>
struct apply
{
- typedef typename symbol_string_impl<N-1>::template apply<typename mpl::next<Begin>::type> next;
+ typedef typename symbol_string_impl<N-1>::template apply<typename Begin::next> next;
static void value(std::string& str)
{
- str += base_unit_symbol_string(typename mpl::deref<Begin>::type()) + ' ';
+ str += base_unit_symbol_string(typename Begin::item()) + ' ';
next::value(str);
}
};
@@ -225,7 +225,7 @@
{
static void value(std::string& str)
{
- str += base_unit_symbol_string(typename mpl::deref<Begin>::type());
+ str += base_unit_symbol_string(typename Begin::item());
};
};
};
@@ -252,8 +252,8 @@
{
static void value(std::string& str)
{
- str += mpl::deref<Begin>::type::symbol();
- scale_symbol_string_impl<N - 1>::template apply<typename mpl::next<Begin>::type>::value(str);
+ str += Begin::item::symbol();
+ scale_symbol_string_impl<N - 1>::template apply<typename Begin::next>::value(str);
}
};
};
@@ -275,10 +275,10 @@
template<class Begin>
struct apply
{
- typedef typename name_string_impl<N-1>::template apply<typename mpl::next<Begin>::type> next;
+ typedef typename name_string_impl<N-1>::template apply<typename Begin::next> next;
static void value(std::string& str)
{
- str += base_unit_name_string(typename mpl::deref<Begin>::type()) + ' ';
+ str += base_unit_name_string(typename Begin::item()) + ' ';
next::value(str);
}
};
@@ -292,7 +292,7 @@
{
static void value(std::string& str)
{
- str += base_unit_name_string(typename mpl::deref<Begin>::type());
+ str += base_unit_name_string(typename Begin::item());
};
};
};
@@ -318,8 +318,8 @@
{
static void value(std::string& str)
{
- str += mpl::deref<Begin>::type::name();
- scale_name_string_impl<N - 1>::template apply<typename mpl::next<Begin>::type>::value(str);
+ str += Begin::item::name();
+ scale_name_string_impl<N - 1>::template apply<typename Begin::next>::value(str);
}
};
};
@@ -476,13 +476,11 @@
struct format_raw_symbol_impl {
template<class Units>
void append_units_to(std::string& str) {
- detail::symbol_string_impl<mpl::size<Units>::value>::template apply<
- typename mpl::begin<Units>::type>::value(str);
+ detail::symbol_string_impl<Units::size::value>::template apply<Units>::value(str);
}
template<class Scale>
void append_scale_to(std::string& str) {
- detail::scale_symbol_string_impl<mpl::size<Scale>::value>::template apply<
- typename mpl::begin<Scale>::type>::value(str);
+ detail::scale_symbol_string_impl<Scale::size::value>::template apply<Scale>::value(str);
}
template<class Unit>
std::string operator()(const Unit& unit) {
@@ -508,13 +506,11 @@
struct format_raw_name_impl {
template<class Units>
void append_units_to(std::string& str) {
- detail::name_string_impl<mpl::size<Units>::value>::template apply<
- typename mpl::begin<Units>::type>::value(str);
+ detail::name_string_impl<(Units::size::value)>::template apply<Units>::value(str);
}
template<class Scale>
void append_scale_to(std::string& str) {
- detail::scale_name_string_impl<mpl::size<Scale>::value>::template apply<
- typename mpl::begin<Scale>::type>::value(str);
+ detail::scale_name_string_impl<Scale::size::value>::template apply<Scale>::value(str);
}
template<class Unit>
std::string operator()(const Unit& unit) {
Modified: branches/release/boost/units/lambda.hpp
==============================================================================
--- branches/release/boost/units/lambda.hpp (original)
+++ branches/release/boost/units/lambda.hpp 2008-07-08 12:48:36 EDT (Tue, 08 Jul 2008)
@@ -56,7 +56,7 @@
template<typename System, typename Dim, typename Arg>
struct multiply_typeof_helper<boost::units::unit<Dim, System>, boost::lambda::lambda_functor<Arg> > {
- typename boost::lambda::lambda_functor<
+ typedef boost::lambda::lambda_functor<
boost::lambda::lambda_functor_base<
boost::lambda::arithmetic_action<boost::lambda::multiply_action>,
tuple<typename boost::lambda::const_copy_argument<const boost::units::unit<Dim, System> >::type, boost::lambda::lambda_functor<Arg> >
Modified: branches/release/boost/units/make_system.hpp
==============================================================================
--- branches/release/boost/units/make_system.hpp (original)
+++ branches/release/boost/units/make_system.hpp 2008-07-08 12:48:36 EDT (Tue, 08 Jul 2008)
@@ -11,8 +11,6 @@
#ifndef BOOST_UNITS_MAKE_SYSTEM_HPP
#define BOOST_UNITS_MAKE_SYSTEM_HPP
-#include <boost/mpl/list/list10.hpp>
-
#include <boost/units/config.hpp>
#include <boost/units/dimensionless_type.hpp>
#include <boost/units/homogeneous_system.hpp>
@@ -77,55 +75,55 @@
template<class T0, class T1>
struct make_system<T0, T1, na, na, na, na, na, na, na, na>
{
- typedef homogeneous_system<typename detail::bubble_sort<mpl::list2<T0, T1> >::type> type;
+ typedef homogeneous_system<typename detail::insertion_sort<list<T0, list<T1, dimensionless_type> > >::type> type;
};
template<class T0, class T1, class T2>
struct make_system<T0, T1, T2, na, na, na, na, na, na, na>
{
- typedef homogeneous_system<typename detail::bubble_sort<mpl::list3<T0, T1, T2> >::type> type;
+ typedef homogeneous_system<typename detail::insertion_sort<list<T0, list<T1, list<T2, dimensionless_type> > > >::type> type;
};
template<class T0, class T1, class T2, class T3>
struct make_system<T0, T1, T2, T3, na, na, na, na, na, na>
{
- typedef homogeneous_system<typename detail::bubble_sort<mpl::list4<T0, T1, T2, T3> >::type> type;
+ typedef homogeneous_system<typename detail::insertion_sort<list<T0, list<T1, list<T2, list<T3, dimensionless_type> > > > >::type> type;
};
template<class T0, class T1, class T2, class T3, class T4>
struct make_system<T0, T1, T2, T3, T4, na, na, na, na, na>
{
- typedef homogeneous_system<typename detail::bubble_sort<mpl::list5<T0, T1, T2, T3, T4> >::type> type;
+ typedef homogeneous_system<typename detail::insertion_sort<list<T0, list<T1, list<T2, list<T3, list<T4, dimensionless_type> > > > > >::type> type;
};
template<class T0, class T1, class T2, class T3, class T4, class T5>
struct make_system<T0, T1, T2, T3, T4, T5, na, na, na, na>
{
- typedef homogeneous_system<typename detail::bubble_sort<mpl::list6<T0, T1, T2, T3, T4, T5> >::type> type;
+ typedef homogeneous_system<typename detail::insertion_sort<list<T0, list<T1, list<T2, list<T3, list<T4, list<T5, dimensionless_type> > > > > > >::type> type;
};
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6>
struct make_system<T0, T1, T2, T3, T4, T5, T6, na, na, na>
{
- typedef homogeneous_system<typename detail::bubble_sort<mpl::list7<T0, T1, T2, T3, T4, T5, T6> >::type> type;
+ typedef homogeneous_system<typename detail::insertion_sort<list<T0, list<T1, list<T2, list<T3, list<T4, list<T5, list<T6, dimensionless_type> > > > > > > >::type> type;
};
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6, class T7>
struct make_system<T0, T1, T2, T3, T4, T5, T6, T7, na, na>
{
- typedef homogeneous_system<typename detail::bubble_sort<mpl::list8<T0, T1, T2, T3, T4, T5, T6, T7> >::type> type;
+ typedef homogeneous_system<typename detail::insertion_sort<list<T0, list<T1, list<T2, list<T3, list<T4, list<T5, list<T6, list<T7, dimensionless_type> > > > > > > > >::type> type;
};
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8>
struct make_system<T0, T1, T2, T3, T4, T5, T6, T7, T8, na>
{
- typedef homogeneous_system<typename detail::bubble_sort<mpl::list9<T0, T1, T2, T3, T4, T5, T6, T7, T8> >::type> type;
+ typedef homogeneous_system<typename detail::insertion_sort<list<T0, list<T1, list<T2, list<T3, list<T4, list<T5, list<T6, list<T7, list<T8, dimensionless_type> > > > > > > > > >::type> type;
};
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9>
struct make_system
{
- typedef homogeneous_system<typename detail::bubble_sort<mpl::list10<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> >::type> type;
+ typedef homogeneous_system<typename detail::insertion_sort<list<T0, list<T1, list<T2, list<T3, list<T4, list<T5, list<T6, list<T7, list<T8, list<T9, dimensionless_type> > > > > > > > > > >::type> type;
};
#endif
Modified: branches/release/boost/units/quantity.hpp
==============================================================================
--- branches/release/boost/units/quantity.hpp (original)
+++ branches/release/boost/units/quantity.hpp 2008-07-08 12:48:36 EDT (Tue, 08 Jul 2008)
@@ -107,6 +107,15 @@
BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y);
}
+ // Need to make sure that the destructor of
+ // Unit which contains the checking is instantiated,
+ // on sun.
+ #ifdef __SUNPRO_CC
+ ~quantity() {
+ unit_type force_unit_instantiation;
+ }
+ #endif
+
//~quantity() { }
this_type& operator=(const this_type& source)
@@ -314,6 +323,7 @@
return *this;
}
+
#ifndef BOOST_NO_SFINAE
/// implicit conversion between value types is allowed if allowed for value types themselves
@@ -358,14 +368,24 @@
return *this;
}
- #ifndef BOOST_NO_SFINAE
+ #if 1
/// implicit conversion between different unit systems is allowed
template<class System2, class Y2>
quantity(const quantity<unit<dimensionless_type, System2>,Y2>& source,
- typename boost::enable_if<detail::is_non_narrowing_conversion<Y2, Y>,
- typename detail::disable_if_is_same<System, System2>::type>::type* = 0,
- typename boost::enable_if<detail::is_dimensionless_system<System2> >::type* = 0) :
+ #ifdef __SUNPRO_CC
+ typename boost::enable_if<
+ boost::mpl::and_<
+ detail::is_non_narrowing_conversion<Y2, Y>,
+ detail::is_dimensionless_system<System2>
+ >
+ >::type* = 0
+ #else
+ typename boost::enable_if<detail::is_non_narrowing_conversion<Y2, Y> >::type* = 0,
+ typename detail::disable_if_is_same<System, System2>::type* = 0,
+ typename boost::enable_if<detail::is_dimensionless_system<System2> >::type* = 0
+ #endif
+ ) :
val_(source.value())
{
BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y);
@@ -374,9 +394,19 @@
/// implicit conversion between different unit systems is allowed
template<class System2, class Y2>
explicit quantity(const quantity<unit<dimensionless_type, System2>,Y2>& source,
- typename boost::disable_if<detail::is_non_narrowing_conversion<Y2, Y>,
- typename detail::disable_if_is_same<System, System2>::type>::type* = 0,
- typename boost::enable_if<detail::is_dimensionless_system<System2> >::type* = 0) :
+ #ifdef __SUNPRO_CC
+ typename boost::enable_if<
+ boost::mpl::and_<
+ boost::mpl::not_<detail::is_non_narrowing_conversion<Y2, Y> >,
+ detail::is_dimensionless_system<System2>
+ >
+ >::type* = 0
+ #else
+ typename boost::disable_if<detail::is_non_narrowing_conversion<Y2, Y> >::type* = 0,
+ typename detail::disable_if_is_same<System, System2>::type* = 0,
+ typename boost::enable_if<detail::is_dimensionless_system<System2> >::type* = 0
+ #endif
+ ) :
val_(static_cast<Y>(source.value()))
{
BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y);
@@ -404,6 +434,8 @@
{
BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y);
}
+
+ #ifndef __SUNPRO_CC
/// implicit assignment between different unit systems is allowed
template<class System2>
@@ -414,6 +446,8 @@
return *this;
}
+ #endif
+
/// implicit conversion to @c value_type is allowed
operator value_type() const { return val_; }
@@ -549,6 +583,28 @@
typedef quantity<unit_type,value_type> type;
};
+/// for sun CC we need to invoke SFINAE at
+/// the top level, otherwise it will silently
+/// return int.
+template<class Dim1, class System1,
+ class Dim2, class System2,
+ class X,
+ class Y>
+struct add_typeof_helper< quantity<unit<Dim1, System1>,X>,quantity<unit<Dim2, System2>,Y> >
+{
+};
+
+template<class Dim,
+ class System,
+ class X,
+ class Y>
+struct add_typeof_helper< quantity<unit<Dim, System>,X>,quantity<unit<Dim, System>,Y> >
+{
+ typedef typename add_typeof_helper<X,Y>::type value_type;
+ typedef unit<Dim, System> unit_type;
+ typedef quantity<unit_type,value_type> type;
+};
+
/// specialize subtract typeof helper
/// INTERNAL ONLY
template<class Unit1,
@@ -562,6 +618,26 @@
typedef quantity<unit_type,value_type> type;
};
+// Force adding different units to fail on sun.
+template<class Dim1, class System1,
+ class Dim2, class System2,
+ class X,
+ class Y>
+struct subtract_typeof_helper< quantity<unit<Dim1, System1>,X>,quantity<unit<Dim2, System2>,Y> >
+{
+};
+
+template<class Dim,
+ class System,
+ class X,
+ class Y>
+struct subtract_typeof_helper< quantity<unit<Dim, System>,X>,quantity<unit<Dim, System>,Y> >
+{
+ typedef typename subtract_typeof_helper<X,Y>::type value_type;
+ typedef unit<Dim, System> unit_type;
+ typedef quantity<unit_type,value_type> type;
+};
+
/// scalar times unit typeof helper
/// INTERNAL ONLY
template<class System,
Modified: branches/release/boost/units/unit.hpp
==============================================================================
--- branches/release/boost/units/unit.hpp (original)
+++ branches/release/boost/units/unit.hpp 2008-07-08 12:48:36 EDT (Tue, 08 Jul 2008)
@@ -13,6 +13,7 @@
#include <boost/static_assert.hpp>
#include <boost/mpl/bool.hpp>
+#include <boost/mpl/assert.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/units/config.hpp>
@@ -47,9 +48,20 @@
this_type& operator=(const this_type&) { }
+ // sun will ignore errors resulting from templates
+ // instantiated in the return type of a function.
+ // Make sure that we get an error anyway by putting.
+ // the check in the destructor.
+ #ifdef __SUNPRO_CC
+ ~unit() {
+ BOOST_MPL_ASSERT((detail::check_system<System, Dim>));
+ BOOST_MPL_ASSERT((is_dimension_list<Dim>));
+ }
+ #else
private:
- BOOST_STATIC_ASSERT((detail::check_system<System, Dim>::value == true));
- BOOST_STATIC_ASSERT((is_dimension_list<Dim>::value == true));
+ BOOST_MPL_ASSERT((detail::check_system<System, Dim>));
+ BOOST_MPL_ASSERT((is_dimension_list<Dim>));
+ #endif
};
}
@@ -105,28 +117,20 @@
/// unit add typeof helper
/// INTERNAL ONLY
-template<class Dim1,
- class Dim2,
+template<class Dim,
class System>
-struct add_typeof_helper< unit<Dim1,System>,unit<Dim2,System> >
+struct add_typeof_helper< unit<Dim,System>,unit<Dim,System> >
{
- // ensure dimension lists are commensurate
- BOOST_STATIC_ASSERT((is_same<Dim1,Dim2>::value == true));
-
- typedef unit<Dim1,System> type;
+ typedef unit<Dim,System> type;
};
/// unit subtract typeof helper
/// INTERNAL ONLY
-template<class Dim1,
- class Dim2,
+template<class Dim,
class System>
-struct subtract_typeof_helper< unit<Dim1,System>,unit<Dim2,System> >
+struct subtract_typeof_helper< unit<Dim,System>,unit<Dim,System> >
{
- // ensure dimension lists are commensurate
- BOOST_STATIC_ASSERT((is_same<Dim1,Dim2>::value == true));
-
- typedef unit<Dim1,System> type;
+ typedef unit<Dim,System> type;
};
/// unit multiply typeof helper for two identical homogeneous systems
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk