Bug 1885602 - Part 5: Implement navigating to the SUMO help topic from the menu heade...
[gecko.git] / dom / bindings / UnionMember.h
blob2fba7910fa0cdfd074f90e22d2d96a26fd9b1668
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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* A class for holding the members of a union. */
9 #ifndef mozilla_dom_UnionMember_h
10 #define mozilla_dom_UnionMember_h
12 #include "mozilla/Alignment.h"
13 #include "mozilla/Attributes.h"
14 #include <utility>
16 namespace mozilla::dom {
18 // The union type has an enum to keep track of which of its UnionMembers has
19 // been constructed.
20 template <class T>
21 class UnionMember {
22 AlignedStorage2<T> mStorage;
24 // Copy construction can't be supported because C++ requires that any enclosed
25 // T be initialized in a way C++ knows about -- that is, by |new| or similar.
26 UnionMember(const UnionMember&) = delete;
28 public:
29 UnionMember() = default;
30 ~UnionMember() = default;
32 template <typename... Args>
33 T& SetValue(Args&&... args) {
34 new (mStorage.addr()) T(std::forward<Args>(args)...);
35 return *mStorage.addr();
38 T& Value() { return *mStorage.addr(); }
39 const T& Value() const { return *mStorage.addr(); }
40 void Destroy() { mStorage.addr()->~T(); }
41 } MOZ_INHERIT_TYPE_ANNOTATIONS_FROM_TEMPLATE_ARGS;
43 } // namespace mozilla::dom
45 #endif // mozilla_dom_UnionMember_h