Skip to content

Commit

Permalink
Update documentation on ad hoc constant limitations.
Browse files Browse the repository at this point in the history
Ad hoc constants no longer have significant limitations with unit labels.
  • Loading branch information
hoffbrinkle committed Dec 31, 2024
1 parent 221d8f4 commit 557b7da
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions docs/reference/constant.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,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

0 comments on commit 557b7da

Please sign in to comment.