Skip to content

Basic: add a workaround for VS2019 #65308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions include/swift/Basic/TaggedUnion.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,24 @@ class TaggedUnionBase<KindHelper, Members,

TaggedUnionBase(Kind theKind) : TheKind(theKind) {}

template <typename T>
static constexpr const bool constructible =
TaggedUnionImpl::is_member_constructible<Members, T>();

public:
/// Construct the union with a value of the given type, which must
/// (ignoring references) be one of the declared members of the union.
template <class T>
TaggedUnionBase(T &&value,
typename std::enable_if<
TaggedUnionImpl::is_member_constructible<Members, T>(),
TaggedUnionImpl::Empty>::type = {}) {
typename std::enable_if<constructible<T>,
TaggedUnionImpl::Empty>::type = {}) {
using TargetType = TaggedUnionImpl::simplify_member_type<T>;
TheKind = StorageType::template kindForMember<TargetType>();
Storage.template emplace<TargetType>(TheKind, std::forward<T>(value));
}

template <class T>
typename std::enable_if<TaggedUnionImpl::is_member_constructible<Members, T>(),
TaggedUnionBase &>::type
typename std::enable_if<constructible<T>, TaggedUnionBase &>::type
operator=(T &&value) {
using TargetType = TaggedUnionImpl::simplify_member_type<T>;
TheKind = StorageType::template kindForMember<TargetType>();
Expand Down Expand Up @@ -155,12 +157,15 @@ class TaggedUnionBase<KindHelper, Members, /*NonTrivial*/ true, /*HasVoid*/ fals

TaggedUnionBase(typename super::Kind kind) : super(kind) {}

template <typename T>
static constexpr const bool constructible =
TaggedUnionImpl::is_member_constructible<Members, T>();

public:
template <class T>
TaggedUnionBase(T &&value,
typename std::enable_if<
TaggedUnionImpl::is_member_constructible<Members, T>(),
TaggedUnionImpl::Empty>::type = {})
typename std::enable_if<constructible<T>,
TaggedUnionImpl::Empty>::type = {})
: super(std::forward<T>(value)) {}

// We want to either define or delete all the special members.
Expand Down Expand Up @@ -236,12 +241,15 @@ class TaggedUnionBase<KindHelper, Members, NonTrivial, /*HasVoid*/ true>
return super::StorageType::template kindForMember<void>();
}

template <typename T>
static constexpr const bool constructible =
TaggedUnionImpl::is_member_constructible<Members, T>();

public:
template <class T>
TaggedUnionBase(T &&value,
typename std::enable_if<
TaggedUnionImpl::is_member_constructible<Members, T>(),
TaggedUnionImpl::Empty>::type = {})
typename std::enable_if<constructible<T>,
TaggedUnionImpl::Empty>::type = {})
: super(std::forward<T>(value)) {}

/// Construct the union in the empty state.
Expand Down