From 122c82a2a17a83b6799b1ca3cd53c0f366b79c03 Mon Sep 17 00:00:00 2001 From: "Liav A." Date: Fri, 26 Jan 2024 16:43:01 +0200 Subject: [PATCH] AK: Add the SetOnce class The SetOnce class is meant to be used as one-time set boolean flag, which is useful for flags that change only once and then stay immutable forever. --- AK/SetOnce.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 AK/SetOnce.h diff --git a/AK/SetOnce.h b/AK/SetOnce.h new file mode 100644 index 00000000000..b64998f73fb --- /dev/null +++ b/AK/SetOnce.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024, Liav A. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +namespace AK { + +class SetOnce { + AK_MAKE_NONCOPYABLE(SetOnce); + AK_MAKE_NONMOVABLE(SetOnce); + +public: + SetOnce() = default; + + void set() + { + m_value = true; + } + + bool was_set() const { return m_value; } + +private: + bool m_value { false }; +}; + +} + +#if USING_AK_GLOBALLY +using AK::SetOnce; +#endif