Skip to content
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
9 changes: 4 additions & 5 deletions au/quantity_point.hh
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,10 @@ class QuantityPoint {
static constexpr Unit unit{};
using Diff = Quantity<Unit, Rep>;

// The default constructor produces a QuantityPoint in a valid but contractually unspecified
// state. It exists to give you an object you can assign to. The main motivating factor for
// including this is to support `std::atomic`, which requires its types to be
// default-constructible.
constexpr QuantityPoint() noexcept : x_{ZERO} {}
// The default constructor produces a QuantityPoint whose value is default constructed. It
// exists to give you an object you can assign to. The main motivating factor for including
// this is to support `std::atomic`, which requires its types to be default-constructible.
constexpr QuantityPoint() noexcept : x_{} {}

template <typename OtherUnit,
typename OtherRep,
Expand Down
13 changes: 8 additions & 5 deletions docs/reference/quantity_point.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,14 @@ class QuantityPoint {
};
```

A default-constructed `QuantityPoint` 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
`QuantityPoint` is to assign to it later on.
A default-constructed `QuantityPoint` default-constructs the underlying type, 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 `QuantityPoint`, because it
poorly communicates intent. The only logically valid operation on a default-constructed
`Quantity` is to assign to it later on.

## Extracting the stored value

Expand Down