nholthaus / units

a compile-time, header-only, dimensional analysis and unit conversion library built on c++14 with no dependencies.
http://nholthaus.github.io/units/
MIT License
947 stars 135 forks source link

Creating new categories #233

Open kunaltyagi opened 4 years ago

kunaltyagi commented 4 years ago
  1. Which version of units you are using master or 3 (doesn't matter)

Is there a way to create new base categories like length, temperature? Based on the inheritance diagram of unit<...> it doesn't seem so.

Essentially, I need to create a couple of non-dimensional units (with user defined conversions between them).

Right now, my functions look like

unitA convert(unitB);
std::tuple<Outunits...> convert(std::tuple<UnitD, Unit E>);  // only a few specializations exist

Can I adapt my usage to make better use of this library?

This is related weakly to the broader discussion in #83

nholthaus commented 4 years ago

In v3 you can specify your own base dimensions arbitrarily, they just need a name and an abbreviation. see here: https://github.com/nholthaus/units/blob/v3.x/include/units/core.h#L1117

On Thu, Sep 12, 2019 at 3:55 AM Kunal Tyagi notifications@github.com wrote:

  1. Which version of units you are using master or 3 (doesn't matter)

Is there a way to create new base categories like length, temperature? Based on the inheritance diagram of unit<...> it doesn't seem so.

Essentially, I need to create a couple of non-dimensional units (with user defined conversions between them).

Right now, my functions look like

unitA convert(unitB); std::tuple convert(std::tuple<UnitD, Unit E>); // only a few specializations exist

Can I adapt my usage to make better use of this library?

This is related weakly to the broader discussion in #83 https://github.com/nholthaus/units/issues/83

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/nholthaus/units/issues/233?email_source=notifications&email_token=ACOYOH64R4ZYXA7XAHD6AIDQJHYX7A5CNFSM4IWAOZOKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HK5FOOA, or mute the thread https://github.com/notifications/unsubscribe-auth/ACOYOHYVHWBQKYYA2NCNBJDQJHYX7ANCNFSM4IWAOZOA .

kunaltyagi commented 4 years ago

In v3 you can specify your own base dimensions arbitrarily

Great. So just using myUnit = units::make_dimension<MyUnitTagStruct>; and with the tag struct requiring only 2 members? Seems awesome. I'll report back on my experiments with v3

Edit

Update

So, I've a system working, I don't know how well designed it is. I've copied some from the "show off thread". My system can be found at this gist. Would this be the correct place to ask for feedback?

Issues

  1. Converting from one basis to another via the convert functions. But there's no ctor which uses the convert function. Is it possible to add that (on the v3.x branch)? I can't think of a simple way to do that.
// My wish: to use the following syntax without using convert function
projections::spherical_projection::theta_t p = 1_x;  // compiler fails to find a conversion (ofc)
  1. Associating a dimension with my custom dimensions. Eg: using tan with my custom theta_t type which is obviously not an angle type