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
952 stars 135 forks source link

`unit_conversion`s as strong type aliases #167

Closed JohelEGP closed 6 years ago

JohelEGP commented 6 years ago

Resolves #160 to prevent having to prefix the unit_conversion tags everywhere so that they're valid outside their namespace here.

The new type trait, strong, maps a unit_conversion to its strong type alias. They are used as late as possible to prevent ODR issues. Manipulators like squared don't use it as they're used in the definition of units. See, for example:

UNIT_ADD(solid_angle, degree_squared, degrees_squared, sq_deg, squared<angle::degrees>)

This declares degrees_squared as a strong type alias of squared<angle::degrees>, and then specializes strong so that strong_t<squared<angle::degrees>> names degrees_squared. If squared used strong_t, then the meaning of squared<angle::degrees> would change after this unit definition.

JohelEGP commented 6 years ago

Here's a diff of errors based on these Compiler Explorer sources. It seems that the lack of strong typing can pull some overloads from elsewhere.

nholthaus commented 6 years ago

looks great. The improvement to the error messages is phenomenal. I pulled the header split PR first so I think once the conflicts are resolved this is ready to go.

JohelEGP commented 6 years ago

Good news. I'll look into into it.

JohelEGP commented 6 years ago

Rebased. clang-format was ran on the conversion_factor renaming.

nholthaus commented 6 years ago

hmm, I must have visual studio set up to autorun it. I'll turn that off.

JohelEGP commented 6 years ago

I meant to say that the code was auto formatted for me. You should turn it on.

nholthaus commented 6 years ago

roger that.