Skip to content

Commit

Permalink
[common] Add precondition checking to copyable_unique_ptr (RobotLocom…
Browse files Browse the repository at this point in the history
…otion#17212)

* [common] Add precondition checking to copyable_unique_ptr
  • Loading branch information
jwnimmer-tri authored May 17, 2022
1 parent 73b033d commit ddd6c96
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions common/copyable_unique_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class copyable_unique_ptr : public std::unique_ptr<T> {
heap-allocated copy of the source object, created using its copy
constructor or `Clone()` method. The currently-held object (if any) is
deleted. */
copyable_unique_ptr & operator=(const T& ref) {
copyable_unique_ptr& operator=(const T& ref) {
std::unique_ptr<T>::reset(CopyOrNull(&ref));
return *this;
}
Expand Down Expand Up @@ -318,7 +318,10 @@ class copyable_unique_ptr : public std::unique_ptr<T> {
shore up this gap in the const correctness protection.
@pre `this != nullptr` reports `true`. */
const T& operator*() const { return *get(); }
const T& operator*() const {
DRAKE_ASSERT(!empty());
return *get();
}

/** Return a writable reference to the contained object (if T is itself not
const). Note that you need write access to this container in order to get
Expand All @@ -336,7 +339,10 @@ class copyable_unique_ptr : public std::unique_ptr<T> {
reference.
@pre `this != nullptr` reports `true`. */
T& operator*() { return *get_mutable(); }
T& operator*() {
DRAKE_ASSERT(!empty());
return *get_mutable();
}

/**@}*/
private:
Expand Down

0 comments on commit ddd6c96

Please sign in to comment.