[ox/std] Add defer
This commit is contained in:
parent
fcdede2064
commit
ff2f13c99f
1
deps/ox/src/ox/std/CMakeLists.txt
vendored
1
deps/ox/src/ox/std/CMakeLists.txt
vendored
@ -23,6 +23,7 @@ add_library(
|
||||
buffer.cpp
|
||||
buildinfo.cpp
|
||||
byteswap.cpp
|
||||
defer.hpp
|
||||
fmt.cpp
|
||||
heapmgr.cpp
|
||||
memops.cpp
|
||||
|
37
deps/ox/src/ox/std/defer.hpp
vendored
Normal file
37
deps/ox/src/ox/std/defer.hpp
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2015 - 2021 gary@drinkingtea.net
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "error.hpp"
|
||||
|
||||
namespace ox {
|
||||
|
||||
template<typename T>
|
||||
class Defer {
|
||||
private:
|
||||
T m_deferredFunc;
|
||||
|
||||
public:
|
||||
Defer(T deferredFunc) {
|
||||
m_deferredFunc = deferredFunc;
|
||||
}
|
||||
|
||||
Defer(const Defer&) = delete;
|
||||
|
||||
~Defer() {
|
||||
m_deferredFunc();
|
||||
}
|
||||
|
||||
Defer &operator=(const Defer&) = delete;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#define oxDefer Defer oxConcat(oxDefer_, __LINE__) = [&]
|
1
deps/ox/src/ox/std/std.hpp
vendored
1
deps/ox/src/ox/std/std.hpp
vendored
@ -12,6 +12,7 @@
|
||||
#include "bit.hpp"
|
||||
#include "bstring.hpp"
|
||||
#include "byteswap.hpp"
|
||||
#include "defer.hpp"
|
||||
#include "defines.hpp"
|
||||
#include "error.hpp"
|
||||
#include "fmt.hpp"
|
||||
|
Loading…
Reference in New Issue
Block a user