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

Default construct rep inside quantity #296

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion au/code/au/quantity.hh
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ class Quantity {

constexpr Quantity(Rep value) : value_{value} {}

Rep value_{0};
Rep value_{};
};

// Force integer division beteween two integer Quantities, in a callsite-obvious way.
Expand Down
16 changes: 11 additions & 5 deletions docs/reference/quantity.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,17 @@ class Quantity {
};
```

A default-constructed `Quantity` is initialized to some value, which helps avoid certain kinds of
memory safety bugs. However, **the value is contractually unspecified**. You can of course look up
that value by reading the source code, but we may change it in the future, and **we would not
consider this to be a breaking change**. The only valid operation on a default-constructed
`Quantity` is to assign to it later on.
A default-constructed `Quantity` is always initialized (which helps avoid certain kinds of memory
safety bugs). It will contain a default-constructed instance of the rep type.

!!! warning
Avoid relying on the _specific value_ of a default-constructed `Quantity`, because it poorly
communicates intent. The only logically valid operation on a default-constructed `Quantity` is
to assign to it later on.

The default value for many rep types, including all fundamental arithmetic types, is `0`.
Instead of relying on this behaviour, initialize your `Quantity` with [`au::ZERO`](./zero.md) to
better communicate your intent.

### Constructing from corresponding quantity

Expand Down
Loading