31template <
typename A,
bool COPY = false>
class Indirection {
33 using element_type = A;
34 Indirection() =
delete;
35 Indirection(A *&&p) : p_{p} {
36 CHECK(p_ &&
"assigning null pointer to Indirection");
39 Indirection(A &&x) : p_{
new A(std::move(x))} {}
40 Indirection(Indirection &&that) : p_{that.p_} {
41 CHECK(p_ &&
"move construction of Indirection from null Indirection");
48 Indirection &operator=(Indirection &&that) {
49 CHECK(that.p_ &&
"move assignment of null Indirection to Indirection");
56 A &value() {
return *p_; }
57 const A &value()
const {
return *p_; }
59 bool operator==(
const A &that)
const {
return *p_ == that; }
60 bool operator==(
const Indirection &that)
const {
return *p_ == *that.p_; }
62 template <
typename... ARGS>
63 static common::IfNoLvalue<Indirection, ARGS...> Make(ARGS &&...args) {
64 return {
new A(std::move(args)...)};
127template <
typename A>
class ForwardOwningPointer {
129 ForwardOwningPointer() {}
130 ForwardOwningPointer(A *p,
void (*del)(A *)) : p_{p}, deleter_{del} {}
131 ForwardOwningPointer(ForwardOwningPointer &&that)
132 : p_{that.p_}, deleter_{that.deleter_} {
135 ForwardOwningPointer &operator=(ForwardOwningPointer &&that) {
138 deleter_ = that.deleter_;
141 ~ForwardOwningPointer() {
147 A &operator*()
const {
return *p_; }
148 A *operator->()
const {
return p_; }
149 operator bool()
const {
return p_ !=
nullptr; }
150 A *get() {
return p_; }
151 auto get()
const {
return reinterpret_cast<std::add_const_t<A> *
>(p_); }
158 void Reset(A *p =
nullptr) {
164 void Reset(A *p,
void (*del)(A *)) {
171 void (*deleter_)(A *){
nullptr};