4 #ifndef DUNE_TO_UNIQUE_PTR_HH 5 #define DUNE_TO_UNIQUE_PTR_HH 36 :
public std::unique_ptr<T>
38 using Super = std::unique_ptr<T>;
71 DUNE_DEPRECATED_MSG(
"Cast to raw pointer is deprecated. Use std::unique_ptr or std::shared_ptr instead.")
72 operator
pointer() noexcept {
return Super::release(); }
75 operator std::unique_ptr<T>() noexcept {
return std::move(static_cast<Super&>(*
this)); }
78 operator std::shared_ptr<T>() noexcept {
return std::move(static_cast<Super&>(*
this)); }
81 explicit operator bool() noexcept {
return bool(static_cast<Super&>(*
this)); }
84 explicit operator bool() const noexcept {
return bool(static_cast<Super const&>(*
this)); }
91 template <
class T,
class... Args>
94 return {
new T(std::forward<Args>(args)...)};
99 #endif // DUNE_TO_UNIQUE_PTR_HH ToUniquePtr< T > makeToUnique(Args &&... args)
Constructs an object of type T and wraps it in a ToUniquePtr,.
Definition: to_unique_ptr.hh:92
An owning pointer wrapper that can be assigned to (smart) pointers. Cannot be copied. Transfers ownership by cast to any (smart) pointer type. Releases the stored pointer on transfer. NOTE: This is an intermediate solution to switch to std::unique_ptr in later releases smoothly.
Definition: to_unique_ptr.hh:35
ToUniquePtr(pointer ptr=pointer()) noexcept
Constructor, stores the pointer.
Definition: to_unique_ptr.hh:54
Dune namespace.
Definition: alignedallocator.hh:9
#define DUNE_DEPRECATED_MSG(text)
Mark some entity as deprecated.
Definition: deprecated.hh:169
ToUniquePtr(std::nullptr_t) noexcept
Constructor, creates a nullptr
Definition: to_unique_ptr.hh:59
Definition of the DUNE_DEPRECATED macro for the case that config.h is not available.
typename Super::pointer pointer
Definition: to_unique_ptr.hh:44