Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation on ad hoc constant limitations. #372

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions docs/reference/constant.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,23 @@ The main advantage of doing this is its conciseness: the constant definition is
line. The built constant also has all of the multiplication and division operators types that
`Constant` supports, as well as its perfect conversion policy to any `Quantity` type.

The only disadvantage is the missing label, which will make printed quantities hard to understand
because the constant will be represented as `[UNLABELED_UNIT]` in the compound label.
The only disadvantage is the unit label for an ad hoc `Constant` will not be specific to that
`Constant`.

If the constant is used in multiple translation units, or if it leads to values that are printed
out, we believe this disadvantage outweighs the benefits, and we recommend a full definition with
a new unit. Otherwise, the ad hoc constant approach may be called for.
```cpp
constexpr auto c = make_constant(meters / second * mag<299'792'458>());

constexpr auto v = (miles / hour)(65.0);

std::cout << v.as(c) << std::endl;
// Output:
// "9.69257e-08 [299792458 m / s]"

// Found in `"au/constants/speed_of_light.hh"`:
std::cout << v.as(SPEED_OF_LIGHT) << std::endl;
// Output:
// "9.69257e-08 c"
```

## `Constant` and unit slots

Expand Down
Loading