Drake
reinit_after_move.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <utility>
4 
5 namespace drake {
6 
46 template <typename T>
48  public:
52 
56  // NOLINTNEXTLINE(runtime/explicit)
57  reinit_after_move(const T& value) : value_(value) {}
58 
61 
62  reinit_after_move(const reinit_after_move&) = default;
65  value_ = std::move(other.value_);
66  other.value_ = T{};
67  }
69  if (this != &other) {
70  value_ = std::move(other.value_);
71  other.value_ = T{};
72  }
73  return *this;
74  }
77 
80  operator T&() { return value_; }
81  operator const T&() const { return value_; }
84  private:
85  T value_{};
86 };
87 
88 } // namespace drake
Definition: automotive_demo.cc:88
Type wrapper that performs value-initialization on the wrapped type, and guarantees that when moving ...
Definition: reinit_after_move.h:47
int value
Definition: copyable_unique_ptr_test.cc:61
reinit_after_move & operator=(const reinit_after_move &)=default
reinit_after_move(reinit_after_move &&other)
Definition: reinit_after_move.h:64
reinit_after_move & operator=(reinit_after_move &&other)
Definition: reinit_after_move.h:68
reinit_after_move()
Constructs a reinit_after_move<T> with a value-initialized wrapped value.
Definition: reinit_after_move.h:51
reinit_after_move(const T &value)
Constructs a reinit_after_move<T> with the given wrapped value.
Definition: reinit_after_move.h:57