|
Boost : |
From: Matthias Schabel (boost_at_[hidden])
Date: 2007-02-12 17:45:12
>> Not necessarily. static_multiply has to be
>> able to operate on an mpl::list.
>
> I don't know where you come up with that requirement. It certainly
> makes sense to me that if you have a library that is as intimately
> tied
> with MPL as this one is that you use the standards created by the MPL.
As Steven pointed out, this is not a detail - how would you write a
template
specialization of mpl::times<> that works for an arbitrary mpl::list?
By defining
my own compile time operators, I can default to mpl lists and
specialize where
necessary.
> quantinty<SI::length> l = 1.5 * ft;
>
> And no I don't really think ft being a quantity is adequate.
You can already do this. Define an imperial unit system with ft as
the unit
of length, then specialize the conversion_helper template:
template<class Y>
class conversion_helper< quantity<unit<imperial::system,length_type>,Y>,
quantity<unit<si::system,length_type>,Y> >
{
public:
static
quantity<unit<si::system,length_type>,Y>
convert(const quantity<unit<imperial::system,length_type>,Y>& source)
{
return quantity<unit<imperial::system,length_type>,Y>::from_value
(source.value()*0.3048);
}
};
static const unit<imperial::system,length_type> ft;
With conversion_helper, you can define basically arbitrary quantity
conversions between any two quantities
(even if they are not dimensionally congruent, if you want, which can
be useful in natural unit systems, for example)...
> quantity<SI::length> cent(cents);
> cent = 2 * meters;
> assert(cent.value() == 200);
I have no idea what this means. Cents == centimeters? If so,
centimeter is not an SI unit of length. And with no
value, the first line doesn't give you a quantity anyway...
> quantity<SI::length> unknown(user_unit);
> unknown = 5 * meters;
> quantity<SI::length> m(meters);
> m = unknown;
> assert(m.value() == 5);
>
> void f_cgs(quantity<CGS::length> l);
> f_cgs(quantity_cast<CGS>(cent));
>
> The syntax is not necessarily what mcs does or would do but the
> concepts
> are what is important.
>
> It's been argued that this adds unnecessary complexity or would cause
> inefficiencies. I don't agree.
I'm sorry to say that I can't make heads or tails out of what you
want here. I would need some real functioning C++
code demonstrating what you think you need to say whether I think
it's possible within the existing framework of
this library...
Matthias
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk