summaryrefslogtreecommitdiff
path: root/AK/Variant.h
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2022-02-14 17:43:49 +0330
committerIdan Horowitz <idan.horowitz@gmail.com>2022-02-15 18:03:02 +0200
commit80e61985632b59acb10a9cf384c7942b2d9bd27d (patch)
tree3b71eef2442d70f13f1568ff8198593cf99101e0 /AK/Variant.h
parent7a58c510e5c86a9d357ea2c4ea09d0771740e066 (diff)
downloadserenity-80e61985632b59acb10a9cf384c7942b2d9bd27d.zip
AK: Conditionally disable a few variant ctors/assignments
We shouldn't let copy/move ctors or assignments be instantiated if the assignee type does not have a copy/move constructor (even if they're not used anywhere).
Diffstat (limited to 'AK/Variant.h')
-rw-r--r--AK/Variant.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/AK/Variant.h b/AK/Variant.h
index 63cc349d19..8425f79f7c 100644
--- a/AK/Variant.h
+++ b/AK/Variant.h
@@ -129,13 +129,13 @@ struct VariantConstructTag {
template<typename T, typename Base>
struct VariantConstructors {
- ALWAYS_INLINE VariantConstructors(T&& t)
+ ALWAYS_INLINE VariantConstructors(T&& t) requires(requires { T(move(t)); })
{
internal_cast().clear_without_destruction();
internal_cast().set(move(t), VariantNoClearTag {});
}
- ALWAYS_INLINE VariantConstructors(const T& t)
+ ALWAYS_INLINE VariantConstructors(const T& t) requires(requires { T(t); })
{
internal_cast().clear_without_destruction();
internal_cast().set(t, VariantNoClearTag {});
@@ -336,7 +336,7 @@ public:
using Detail::MergeAndDeduplicatePacks<Detail::VariantConstructors<Ts, Variant<Ts...>>...>::MergeAndDeduplicatePacks;
template<typename T, typename StrippedT = RemoveCVReference<T>>
- void set(T&& t) requires(can_contain<StrippedT>())
+ void set(T&& t) requires(can_contain<StrippedT>() && requires { StrippedT(forward<T>(t)); })
{
constexpr auto new_index = index_of<StrippedT>();
Helper::delete_(m_index, m_data);
@@ -345,7 +345,7 @@ public:
}
template<typename T, typename StrippedT = RemoveCVReference<T>>
- void set(T&& t, Detail::VariantNoClearTag) requires(can_contain<StrippedT>())
+ void set(T&& t, Detail::VariantNoClearTag) requires(can_contain<StrippedT>() && requires { StrippedT(forward<T>(t)); })
{
constexpr auto new_index = index_of<StrippedT>();
new (m_data) StrippedT(forward<T>(t));