AuROXTL/Include/auROXTL/Objects/ResetMember.hpp

44 lines
816 B
C++
Raw Normal View History

2022-08-26 12:47:17 +00:00
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: ResetMember.hpp
Date: 2022-08-26
Author: Reece
***/
#pragma once
template <class T, class ...Args>
static void AuResetMember(T &ref, Args &&...args)
2022-08-26 12:47:17 +00:00
{
if constexpr (AuIsClass_v<T>)
{
ref.~T();
AuMemset(&ref, 0, sizeof(ref));
new (&ref) T(AuForward<Args>(args)...);
}
else if constexpr (AuIsArray_v<T>)
{
for (AU_ITERATE_N(i, AuArraySize(ref)))
{
AuResetMember(ref[i]);
}
}
else
{
ref = T {};
}
2022-08-26 12:47:17 +00:00
}
template <class T>
static void AuResetMember(AuSPtr<T> &ref)
{
ref.reset();
}
namespace Aurora::Memory
{
struct ByteBuffer;
}
template <class T>
static void AuResetMember(Aurora::Memory::ByteBuffer &ref);