Move Box alloc/dealloc functions to guard object
diff --git a/gen/src/write.rs b/gen/src/write.rs
index cbad93c..44978f1 100644
--- a/gen/src/write.rs
+++ b/gen/src/write.rs
@@ -1420,14 +1420,18 @@
let instance = ident.to_symbol();
writeln!(out, "template <>");
- writeln!(out, "{} *Box<{}>::alloc() noexcept {{", inner, inner);
+ writeln!(
+ out,
+ "{} *Box<{}>::allocation::alloc() noexcept {{",
+ inner, inner,
+ );
writeln!(out, " return cxxbridge1$box${}$alloc();", instance);
writeln!(out, "}}");
writeln!(out, "template <>");
writeln!(
out,
- "void Box<{}>::dealloc({} *ptr) noexcept {{",
+ "void Box<{}>::allocation::dealloc({} *ptr) noexcept {{",
inner, inner,
);
writeln!(out, " cxxbridge1$box${}$dealloc(ptr);", instance);
diff --git a/include/cxx.h b/include/cxx.h
index a1e1700..52136cc 100644
--- a/include/cxx.h
+++ b/include/cxx.h
@@ -227,9 +227,8 @@
private:
class uninit;
+ class allocation;
Box(uninit) noexcept;
- static T *alloc() noexcept;
- static void dealloc(T *) noexcept;
void drop() noexcept;
T *ptr;
};
@@ -552,6 +551,14 @@
class Box<T>::uninit {};
template <typename T>
+class Box<T>::allocation {
+public:
+ static T *alloc() noexcept;
+ static void dealloc(T *) noexcept;
+ T *ptr;
+};
+
+template <typename T>
Box<T>::Box(const Box &other) : Box(*other) {}
template <typename T>
@@ -560,12 +567,12 @@
}
template <typename T>
-Box<T>::Box(const T &val) : ptr(alloc()) {
+Box<T>::Box(const T &val) : ptr(allocation::alloc()) {
::new (this->ptr) T(val);
}
template <typename T>
-Box<T>::Box(T &&val) : ptr(alloc()) {
+Box<T>::Box(T &&val) : ptr(allocation::alloc()) {
::new (this->ptr) T(std::move(val));
}
@@ -582,7 +589,7 @@
if (this->ptr) {
**this = *other;
} else {
- this->ptr = alloc();
+ this->ptr = allocation::alloc();
::new (this->ptr) T(*other);
}
}
@@ -622,7 +629,8 @@
template <typename T>
template <typename... Fields>
Box<T> Box<T>::in_place(Fields &&... fields) {
- return from_raw(::new (alloc()) T{std::forward<Fields>(fields)...});
+ return from_raw(::new (allocation::alloc())
+ T{std::forward<Fields>(fields)...});
}
template <typename T>