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

Split headers #171

Closed JohelEGP closed 6 years ago

JohelEGP commented 6 years ago

Resolves #164.

How does it look like so far? If it's good, I'll continue with the rest of dimensions.

JohelEGP commented 6 years ago

Consider the following program.

#include <units/length.h>

using namespace units::literals;
const auto sq_m = 2_m * 2_m;

In face of strong type aliases for units, it would result in a compile-time error since the type of 2_m * 2_m would be incomplete. It works today because everything's an alias.

JohelEGP commented 6 years ago

I tried to rebase the first commit, by first doing a git mv include/units.h include/units/core.h and then moving non-core functionality into units.h, in order to reduce the number of apparent changed lines and ease review. It failed, and worse, the changed lines count increased. I think it has to do with the fact that units.h still exists, and thus the git mv doesn't help.

nholthaus commented 6 years ago

@johelegp per your earlier comment... yikes. We can't guarantee (and don't want to) that a definition will exist for every ephemeral unit type. That sounds like a show-stopper for strong type aliases, at least for unit.

JohelEGP commented 6 years ago

As explained above (https://github.com/nholthaus/units/pull/171#issuecomment-411916790), the reason it would result in a compile-time error is because core.h would include the forward declaration of square_meter_t and specialization of traits::strong or similar for it, which the operator would use for its return type. Ephemeral units don't need that.

JohelEGP commented 6 years ago

The headers have been split.