[+] C#-like using with RAII semantics. Use: AU_USING(pPointer/ref, MethodName)
This commit is contained in:
parent
d2200907da
commit
6b9a364a91
@ -289,3 +289,5 @@ struct AuStringOwnedException : AuStringException
|
|||||||
#define AU_EMIT_FIRST_COMMA_OTHERS(n),n
|
#define AU_EMIT_FIRST_COMMA_OTHERS(n),n
|
||||||
|
|
||||||
#include "Objects/Objects.hpp"
|
#include "Objects/Objects.hpp"
|
||||||
|
|
||||||
|
#include "AU_USING.hpp"
|
39
Include/auROXTL/AU_USING.hpp
Normal file
39
Include/auROXTL/AU_USING.hpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/***
|
||||||
|
Copyright (C) 2024 Jamie Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||||
|
|
||||||
|
File: AU_USING.hpp
|
||||||
|
Date: 2024-07-30
|
||||||
|
Author: Reece
|
||||||
|
***/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace __audetail
|
||||||
|
{
|
||||||
|
template <typename T_t>
|
||||||
|
struct __au_using
|
||||||
|
{
|
||||||
|
T_t *pThat;
|
||||||
|
using CB_t = void (T_t:: *)();
|
||||||
|
CB_t cb;
|
||||||
|
|
||||||
|
__au_using(T_t &that, CB_t cb) :
|
||||||
|
cb(cb),
|
||||||
|
pThat(&that)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
__au_using(T_t *that, CB_t cb) :
|
||||||
|
cb(cb),
|
||||||
|
pThat(that)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
~__au_using()
|
||||||
|
{
|
||||||
|
((pThat)->*(cb))();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#define AU_USING(pPointer, method) \
|
||||||
|
__audetail::__au_using<AuRemovePointer_t<AuRemoveReference_t<decltype(*pPointer)>>> AU_CONCAT(__stack_using, __COUNTER__)( \
|
||||||
|
pPointer, \
|
||||||
|
&AuRemovePointer_t<AuRemoveReference_t<decltype(*pPointer)>>::method);
|
Loading…
Reference in New Issue
Block a user