alpaqa 1.0.0a12
Nonconvex constrained optimization
Loading...
Searching...
No Matches
copyable_unique_ptr.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4
5namespace alpaqa::util {
6
7template <class T>
9 copyable_unique_ptr(std::unique_ptr<T> ptr) : ptr{std::move(ptr)} {}
14 this->ptr = o.ptr ? std::make_unique<T>(*o.ptr) : nullptr;
15 return *this;
16 }
19
20 operator std::unique_ptr<T> &() & { return ptr; }
21 operator const std::unique_ptr<T> &() const & { return ptr; }
22 operator std::unique_ptr<T> &&() && { return std::move(ptr); }
23
24 std::unique_ptr<T> &operator->() { return ptr; }
25 const std::unique_ptr<T> &operator->() const { return ptr; }
26 auto &operator*() { return *ptr; }
27 auto &operator*() const { return *ptr; }
28
29 std::unique_ptr<T> ptr;
30};
31
32} // namespace alpaqa::util
constexpr const auto inf
Definition config.hpp:85
copyable_unique_ptr & operator=(const copyable_unique_ptr &o)
copyable_unique_ptr(copyable_unique_ptr &&) noexcept=default
copyable_unique_ptr(const copyable_unique_ptr &o)
copyable_unique_ptr(std::unique_ptr< T > ptr)
const std::unique_ptr< T > & operator->() const