|
Boost : |
From: Matthias Schabel (boost_at_[hidden])
Date: 2007-02-15 15:54:46
> I apologize. The comparisons in dimension.hpp are
> currently hard coded to use operator<. You'll need
> to fix sort and merge.
No need to apologize - I appreciate the effort you put into
optimization.
This will be a bit more complicated, unfortunately. The code for the
merge
was relatively straightforward to add:
template<int N1, int N2>
struct merge_dimensions_impl {
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 merge_dimensions_func<
(less<dim1,dim2>::value == true),
(boost::is_same<dim1,dim2>::value == true)>::template
apply<
Begin1,
Begin2,
N1,
N2
>::type type;
};
};
but in the partition you only pass the tag value, so I can't just
drop less<> in...
I'll need to pass the whole dim<>, then insert using less<>...
template<int N>
struct partition_dims_forward_impl
{
template<typename Begin, typename State, long Value>
struct apply
{
typedef typename Begin::item::tag_type::value val;
typedef typename partition_dims_forward_impl<N -
1>::template apply<
typename Begin::next,
typename partition_dims_state_insert<((val::value) <
Value)>::template
apply<State, typename Begin::item>::type,
Value
>::type type;
};
};
In addition, modifying the merge appears to cause problems with
dimensionless units...sigh.
On a positive note, I think multiplication/division of units should
just work once
the sort works correctly. Unit conversion will be a little more
complicated; I think
it will work with two constraints:
1) The target unit may only have one instance of each tag (no
repeated tags with different
systems). Otherwise, the conversion becomes ambiguous.
2) The source unit must have exactly the same set of tags as the
target unit.
To do conversion, we'll have to pull out a list of all list elements
having a given tag, then
convert the ones not in the same system as the same tag in the target
unit, then merge.
Anyway, this is probably not interesting to anyone...don't mind my
blathering...
Matthias
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk