summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Dino Radakovic <dinor@google.com>2023-06-26 10:31:09 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2023-06-26 10:32:09 -0700
commit20089ec0e4cd409cb5428223db168f5e88d7035f (patch)
treee0020bea877d6139581c2917c8cd358eb38d7a70
parent474d21b580e2765aec2e85d2995bf45820be258e (diff)
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
-rw-r--r--absl/functional/internal/any_invocable.h31
1 files changed, 16 insertions, 15 deletions
diff --git a/absl/functional/internal/any_invocable.h b/absl/functional/internal/any_invocable.h
index a52fa876..f096bb02 100644
--- a/absl/functional/internal/any_invocable.h
+++ b/absl/functional/internal/any_invocable.h
@@ -440,11 +440,11 @@ class CoreImpl {
CoreImpl() noexcept : manager_(EmptyManager), invoker_(nullptr) {}
- enum class TargetType : int {
- kPointer = 0,
- kCompatibleAnyInvocable = 1,
- kIncompatibleAnyInvocable = 2,
- kOther = 3,
+ enum class TargetType {
+ kPointer,
+ kCompatibleAnyInvocable,
+ kIncompatibleAnyInvocable,
+ kOther,
};
// Note: QualDecayedTRef here includes the cv-ref qualifiers associated with
@@ -466,8 +466,7 @@ class CoreImpl {
// NOTE: We only use integers instead of enums as template parameters in
// order to work around a bug on C++14 under MSVC 2017.
// See b/236131881.
- Initialize<static_cast<int>(kTargetType), QualDecayedTRef>(
- std::forward<F>(f));
+ Initialize<kTargetType, QualDecayedTRef>(std::forward<F>(f));
}
// Note: QualTRef here includes the cv-ref qualifiers associated with the
@@ -518,8 +517,8 @@ class CoreImpl {
invoker_ = nullptr;
}
- template <int target_type, class QualDecayedTRef, class F,
- absl::enable_if_t<target_type == 0, int> = 0>
+ template <TargetType target_type, class QualDecayedTRef, class F,
+ absl::enable_if_t<target_type == TargetType::kPointer, int> = 0>
void Initialize(F&& f) {
// This condition handles types that decay into pointers, which includes
// function references. Since function references cannot be null, GCC warns
@@ -543,8 +542,9 @@ class CoreImpl {
InitializeStorage<QualDecayedTRef>(std::forward<F>(f));
}
- template <int target_type, class QualDecayedTRef, class F,
- absl::enable_if_t<target_type == 1, int> = 0>
+ template <TargetType target_type, class QualDecayedTRef, class F,
+ absl::enable_if_t<
+ target_type == TargetType::kCompatibleAnyInvocable, int> = 0>
void Initialize(F&& f) {
// In this case we can "steal the guts" of the other AnyInvocable.
f.manager_(FunctionToCall::relocate_from_to, &f.state_, &state_);
@@ -555,8 +555,9 @@ class CoreImpl {
f.invoker_ = nullptr;
}
- template <int target_type, class QualDecayedTRef, class F,
- absl::enable_if_t<target_type == 2, int> = 0>
+ template <TargetType target_type, class QualDecayedTRef, class F,
+ absl::enable_if_t<
+ target_type == TargetType::kIncompatibleAnyInvocable, int> = 0>
void Initialize(F&& f) {
if (f.HasValue()) {
InitializeStorage<QualDecayedTRef>(std::forward<F>(f));
@@ -566,8 +567,8 @@ class CoreImpl {
}
}
- template <int target_type, class QualDecayedTRef, class F,
- typename = absl::enable_if_t<target_type == 3>>
+ template <TargetType target_type, class QualDecayedTRef, class F,
+ typename = absl::enable_if_t<target_type == TargetType::kOther>>
void Initialize(F&& f) {
InitializeStorage<QualDecayedTRef>(std::forward<F>(f));
}