Boost logo

Boost :

From: Dan W. (danw_at_[hidden])
Date: 2004-01-11 19:09:47


Matthias Schabel wrote:

> While all this discussion about abstract qualities that a dimensional
> analysis/units library
> should have is interesting off and on, from the standpoint of an
> implementer I think it would
> be vastly more useful for prospective users of such a library to
> produce syntactically correct
> C++ snippets of how they envision the library functioning. Both
> desired functionality/syntax
> and potential errors that should be caught would be useful test cases.
> It would make things
> much simpler than trying to hit a diffuse cloud of vaguely conceptual
> meanderings and I
> think could also help to keep the discussion more tightly focused on
> implementation/interface
> issues most salient to Boost.

namespace boost::dimensional_units_analysis_library::units
{

unit<imperial_set> inches, feet, yards;
unit<metric_set> um, mm, m, km;

}
namespace boost::dimensional_units_analysis_library::conversions
{
//mplicit<typename S::unit1, int M, typename S::unit2>
// instantiates two template conversion functions, or more.
//...then...
//template<whatever>
//class unit
//{
// template< typename I >
// unit( I const & i ): v_(mmpl_conv<type>(i)) {}
// template< typename X > explicit
// unit( X const & x ): v_(xxpl_conv<type>(x)) {}
template mplicit<yards,3,feet>;
template mplicit<feet,12,inches>;
template mplicit<km,1000,m>;
template mplicit<m,1000,mm>;
template mplicit<mm,1000,um>;
template xplicit<inches,mm>(25.4d);

}
namespace boost::dimensional_units_analysis_library::dim_qtys
{

template quantity<relative,metric_set,metric_distance>;
template quantity<relative,imperial_set,imperial_distance>;
template quantity<absolute,metric_set,metric_position>;
template quantity<absolute,imperial_set,imperial_position>;//:)

}
int main()
{
    using boost::units::blah_blah::allin1::abbrv;
    set_default_unit(imperial_set,inches);
    set_default_unit(metric_set,mm);
    set_default_value_type(int);
    set_default_unity_val(256000);
    template< typename T >
    typedef std::pair<T,T> xy_coord<T>;
    typedef xy_coord< metric_distance > m_xydispl;
    typedef xy_coord< imperial_distance > i_xydispl;
    typedef xy_coord< metric_position > m_xypos;
    typedef xy_coord< metric_position > i_xypos;
    //enough! ;-)
    i_xpos imperial_xy_position(1,2);
    place_std_component(TO92,imperial_xy_position); //ok
    m_xpos metric_xy_position(17,23);
    place_smt_component(_102,metric_xy_position); //ok
    place_std_component(TO92,metric_xy_position);//ERROR, explicit conv.
    metric_xy_position *= 2; //ERROR, can't multiply abs. position
    //... and so on.
    return 0;
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk