Dune Core Modules (2.6.0)

to_unique_ptr.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4#ifndef DUNE_TO_UNIQUE_PTR_HH
5#define DUNE_TO_UNIQUE_PTR_HH
6
7#include <memory>
8
10
11namespace Dune
12{
16
34 template <class T>
36 : public std::unique_ptr<T>
37 {
38 using Super = std::unique_ptr<T>;
39
40 public:
41 // Member types:
43
44 using pointer = typename Super::pointer;
45
47
48
49 public:
50 // Constructors:
52
54 ToUniquePtr(pointer ptr = pointer()) noexcept
55 : Super(ptr)
56 {}
57
59 ToUniquePtr(std::nullptr_t) noexcept
60 : Super(nullptr)
61 {}
62
64
65
66 public:
67 // Conversion operators:
69
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(); }
73
75 operator std::unique_ptr<T>() noexcept { return std::move(static_cast<Super&>(*this)); }
76
78 operator std::shared_ptr<T>() noexcept { return std::move(static_cast<Super&>(*this)); }
79
81 explicit operator bool() noexcept { return bool(static_cast<Super&>(*this)); }
82
84 explicit operator bool() const noexcept { return bool(static_cast<Super const&>(*this)); }
85
87 };
88
89
91 template <class T, class... Args>
93 {
94 return {new T(std::forward<Args>(args)...)};
95 }
96
97} // end namespace Dune
98
99#endif // DUNE_TO_UNIQUE_PTR_HH
An owning pointer wrapper that can be assigned to (smart) pointers. Cannot be copied....
Definition: to_unique_ptr.hh:37
ToUniquePtr< T > makeToUnique(Args &&... args)
Constructs an object of type T and wraps it in a ToUniquePtr,.
Definition: to_unique_ptr.hh:92
ToUniquePtr(pointer ptr=pointer()) noexcept
Constructor, stores the pointer.
Definition: to_unique_ptr.hh:54
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.
#define DUNE_DEPRECATED_MSG(text)
Mark some entity as deprecated.
Definition: deprecated.hh:169
Dune namespace.
Definition: alignedallocator.hh:10
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 24, 23:30, 2024)