Commit 20089ec0 by Dino Radakovic Committed by Copybara-Service

AnyInvocable: Use enums instead of ints in initialization overload set

This trick was introduced to work around a compiler bug in msvc 2017, which abseil doesn't support anymore: https://github.com/google/oss-policies-info/blob/3aa4b98f497fdfac983b8de78cf6bd693cb0cf4f/foundational-cxx-support-matrix.md

PiperOrigin-RevId: 543477428
Change-Id: I332c1b359b75811536ce900d3166979ac3c196a3
parent 474d21b5
...@@ -440,11 +440,11 @@ class CoreImpl { ...@@ -440,11 +440,11 @@ class CoreImpl {
CoreImpl() noexcept : manager_(EmptyManager), invoker_(nullptr) {} CoreImpl() noexcept : manager_(EmptyManager), invoker_(nullptr) {}
enum class TargetType : int { enum class TargetType {
kPointer = 0, kPointer,
kCompatibleAnyInvocable = 1, kCompatibleAnyInvocable,
kIncompatibleAnyInvocable = 2, kIncompatibleAnyInvocable,
kOther = 3, kOther,
}; };
// Note: QualDecayedTRef here includes the cv-ref qualifiers associated with // Note: QualDecayedTRef here includes the cv-ref qualifiers associated with
...@@ -466,8 +466,7 @@ class CoreImpl { ...@@ -466,8 +466,7 @@ class CoreImpl {
// NOTE: We only use integers instead of enums as template parameters in // NOTE: We only use integers instead of enums as template parameters in
// order to work around a bug on C++14 under MSVC 2017. // order to work around a bug on C++14 under MSVC 2017.
// See b/236131881. // See b/236131881.
Initialize<static_cast<int>(kTargetType), QualDecayedTRef>( Initialize<kTargetType, QualDecayedTRef>(std::forward<F>(f));
std::forward<F>(f));
} }
// Note: QualTRef here includes the cv-ref qualifiers associated with the // Note: QualTRef here includes the cv-ref qualifiers associated with the
...@@ -518,8 +517,8 @@ class CoreImpl { ...@@ -518,8 +517,8 @@ class CoreImpl {
invoker_ = nullptr; invoker_ = nullptr;
} }
template <int target_type, class QualDecayedTRef, class F, template <TargetType target_type, class QualDecayedTRef, class F,
absl::enable_if_t<target_type == 0, int> = 0> absl::enable_if_t<target_type == TargetType::kPointer, int> = 0>
void Initialize(F&& f) { void Initialize(F&& f) {
// This condition handles types that decay into pointers, which includes // This condition handles types that decay into pointers, which includes
// function references. Since function references cannot be null, GCC warns // function references. Since function references cannot be null, GCC warns
...@@ -543,8 +542,9 @@ class CoreImpl { ...@@ -543,8 +542,9 @@ class CoreImpl {
InitializeStorage<QualDecayedTRef>(std::forward<F>(f)); InitializeStorage<QualDecayedTRef>(std::forward<F>(f));
} }
template <int target_type, class QualDecayedTRef, class F, template <TargetType target_type, class QualDecayedTRef, class F,
absl::enable_if_t<target_type == 1, int> = 0> absl::enable_if_t<
target_type == TargetType::kCompatibleAnyInvocable, int> = 0>
void Initialize(F&& f) { void Initialize(F&& f) {
// In this case we can "steal the guts" of the other AnyInvocable. // In this case we can "steal the guts" of the other AnyInvocable.
f.manager_(FunctionToCall::relocate_from_to, &f.state_, &state_); f.manager_(FunctionToCall::relocate_from_to, &f.state_, &state_);
...@@ -555,8 +555,9 @@ class CoreImpl { ...@@ -555,8 +555,9 @@ class CoreImpl {
f.invoker_ = nullptr; f.invoker_ = nullptr;
} }
template <int target_type, class QualDecayedTRef, class F, template <TargetType target_type, class QualDecayedTRef, class F,
absl::enable_if_t<target_type == 2, int> = 0> absl::enable_if_t<
target_type == TargetType::kIncompatibleAnyInvocable, int> = 0>
void Initialize(F&& f) { void Initialize(F&& f) {
if (f.HasValue()) { if (f.HasValue()) {
InitializeStorage<QualDecayedTRef>(std::forward<F>(f)); InitializeStorage<QualDecayedTRef>(std::forward<F>(f));
...@@ -566,8 +567,8 @@ class CoreImpl { ...@@ -566,8 +567,8 @@ class CoreImpl {
} }
} }
template <int target_type, class QualDecayedTRef, class F, template <TargetType target_type, class QualDecayedTRef, class F,
typename = absl::enable_if_t<target_type == 3>> typename = absl::enable_if_t<target_type == TargetType::kOther>>
void Initialize(F&& f) { void Initialize(F&& f) {
InitializeStorage<QualDecayedTRef>(std::forward<F>(f)); InitializeStorage<QualDecayedTRef>(std::forward<F>(f));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment