Bug 1842773 - Part 5: Add ArrayBuffer.prototype.{maxByteLength,resizable} getters...
[gecko.git] / dom / indexedDB / FlippedOnce.h
blob9ef2383a7ceaba524e448cdef70a7a666f504138
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_indexeddb_flippedonce_h__
8 #define mozilla_dom_indexeddb_flippedonce_h__
10 #include "mozilla/Assertions.h"
11 #include "mozilla/Attributes.h"
13 namespace mozilla {
15 // A state-restricted bool, which can only be flipped once. It isn't required to
16 // be flipped during its lifetime.
17 template <bool Initial>
18 class FlippedOnce {
19 public:
20 FlippedOnce(const FlippedOnce&) = delete;
21 FlippedOnce& operator=(const FlippedOnce&) = delete;
22 FlippedOnce(FlippedOnce&&) = default;
23 FlippedOnce& operator=(FlippedOnce&&) = default;
25 constexpr FlippedOnce() = default;
27 MOZ_IMPLICIT constexpr operator bool() const { return mValue; };
29 constexpr void Flip() {
30 MOZ_ASSERT(mValue == Initial);
31 EnsureFlipped();
34 constexpr void EnsureFlipped() { mValue = !Initial; }
36 private:
37 bool mValue = Initial;
39 } // namespace mozilla
41 #endif