summaryrefslogtreecommitdiff
path: root/asl/box.hpp
diff options
context:
space:
mode:
authorSteven Le Rouzic <steven.lerouzic@gmail.com>2024-11-22 17:13:03 +0100
committerSteven Le Rouzic <steven.lerouzic@gmail.com>2024-12-20 15:35:58 +0100
commit58bb86fd2f0ecd740fc5bc8078de44221c12c70a (patch)
tree79e83f044d643211d3f9ebfd933e9dea92b2d04e /asl/box.hpp
parentf5ef1937eafb3d96b3683d92639a193694210c70 (diff)
Add a niche to box
Diffstat (limited to 'asl/box.hpp')
-rw-r--r--asl/box.hpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/asl/box.hpp b/asl/box.hpp
index d8ccd36..7556d76 100644
--- a/asl/box.hpp
+++ b/asl/box.hpp
@@ -16,15 +16,18 @@ class box
ASL_NO_UNIQUE_ADDRESS Allocator m_alloc;
public:
- explicit constexpr box(T* ptr = nullptr)
+ explicit constexpr box(niche)
requires default_constructible<Allocator>
- : m_ptr{ptr}
+ : m_ptr{nullptr}
+ , m_alloc{}
{}
-
+
constexpr box(T* ptr, Allocator alloc)
: m_ptr{ptr}
, m_alloc{ASL_MOVE(alloc)}
- {}
+ {
+ ASL_ASSERT(m_ptr != nullptr);
+ }
constexpr box(box&& other)
: m_ptr{exchange(other.m_ptr, nullptr)}
@@ -77,6 +80,11 @@ public:
ASL_ASSERT(m_ptr != nullptr);
return m_ptr;
}
+
+ constexpr bool operator==(niche) const
+ {
+ return m_ptr == nullptr;
+ }
};
template<is_object T, allocator Allocator = DefaultAllocator, typename... Args>