mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-28 05:11:37 +00:00
guest_stack_var: allow creation without constructing underlying type
This commit is contained in:
parent
292fe71e05
commit
be2ebebfda
1 changed files with 10 additions and 4 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
// DO NOT use this type as anything other than a local variable.
|
// DO NOT use this type as anything other than a local variable.
|
||||||
// This includes returning. It'll cause memory to leak in the guest stack!
|
// This includes returning. It'll cause memory to leak in the guest stack!
|
||||||
|
|
||||||
template<typename T>
|
template<typename T, bool Init = true>
|
||||||
class guest_stack_var
|
class guest_stack_var
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
@ -36,19 +36,25 @@ public:
|
||||||
guest_stack_var(Args&&... args)
|
guest_stack_var(Args&&... args)
|
||||||
{
|
{
|
||||||
AllocGuestStackMemory();
|
AllocGuestStackMemory();
|
||||||
new (get()) T(std::forward<Args>(args)...);
|
|
||||||
|
if (Init)
|
||||||
|
new (get()) T(std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
guest_stack_var(const guest_stack_var<T>& other)
|
guest_stack_var(const guest_stack_var<T>& other)
|
||||||
{
|
{
|
||||||
AllocGuestStackMemory();
|
AllocGuestStackMemory();
|
||||||
new (get()) T(*other->get());
|
|
||||||
|
if (Init)
|
||||||
|
new (get()) T(*other->get());
|
||||||
}
|
}
|
||||||
|
|
||||||
guest_stack_var(guest_stack_var<T>&& other)
|
guest_stack_var(guest_stack_var<T>&& other)
|
||||||
{
|
{
|
||||||
AllocGuestStackMemory();
|
AllocGuestStackMemory();
|
||||||
new (get()) T(std::move(*other->get()));
|
|
||||||
|
if (Init)
|
||||||
|
new (get()) T(std::move(*other->get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
~guest_stack_var()
|
~guest_stack_var()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue