
AMDG Deane Yang wrote:
Zach Laine wrote:
Specifically,
quantity<force> F(2.0*newton); quantity<length> dx(2.0*meter); F.value() = dx.value();
is an abomination and should be impossible. If I really want to do this, why not make me go through the constructor, so that attention is more obviously called to what I'm doing? I could also live with using a purposely ugly cast here, but since quantity_cast() has some perfectly legitimate and safe uses, I would much prefer a different syntax that draws attention to this unsafe act, such as quantity_reinterpret_cast().
I agree completely with Zach's views on this. It's OK to have a const member function .value() but not a mutating one.
I and a lot of other users badly need support for Imperial units. As it stands now, we will each be required to write nearly identical code to do so. This should be included in the library.
Matthias Schabel wrote:
The problem with these non-standard units is that they don't really form a well-defined unit system. ... We have, however, supplied a number of examples of how to roll your own unit system... )
I agree with Zach and also want to be able to define units without having to "roll my own unit system".
I have contemplated something along the lines of //this is what you need to do already //to get feet struct foot_tag {}; template<> struct unit_info<length_tag, foot_tag> { static const char* name() { return("foot") } static const char* symbol() { return("ft") } }; //converting feet to meters template<> struct base_unit_converter<length_tag, foot_tag, SI::system_tag> { typedef double type; static type value() { return(...) } }; //converting meters to feet template<> struct base_unit_converter<length_tag, SI::system_tag, foot_tag> { typedef double type; static type value() { return(...) } }; Now feet are defined independently of other base units and can be easily combined with any other set of units: typedef make_system< mpl::map< mpl::pair<length_tag, foot_tag>, mpl::pair<mass_tag, SI::system_tag>, mpl::pair<time_tag, SI::system_tag> >
::type FKS_system; (feet-kilograms-seconds)
From an implementation standpoint the only difficulty is in making a mixed system such as inches * miles / furlongs work without ending up with a mess. In Christ, Steven Watanabe