mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-18 15:32:22 +00:00
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.
This commit is contained in:
parent
de2cad02aa
commit
122c82a2a1
Notes:
sideshowbarker
2024-07-17 03:27:40 +09:00
Author: https://github.com/supercomputer7
Commit: 122c82a2a1
Pull-request: https://github.com/SerenityOS/serenity/pull/24071
Reviewed-by: https://github.com/ADKaster ✅
1 changed files with 36 additions and 0 deletions
36
AK/SetOnce.h
Normal file
36
AK/SetOnce.h
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024, Liav A. <liavalb@hotmail.co.il>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/Noncopyable.h>
|
||||||
|
#include <AK/Types.h>
|
||||||
|
|
||||||
|
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
|
Loading…
Add table
Add a link
Reference in a new issue