Skip to content

Commit c0788c7

Browse files
dinordcopybara-github
authored andcommitted
absl: Deprecate ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
Always define it as `1`. CTAD is a C++17 feature, and Abseil does not support older versions of the language. PiperOrigin-RevId: 729144923 Change-Id: I13572569004d7f0b56a2c11f264b7a3de15927b9
1 parent 9f3d4d7 commit c0788c7

File tree

6 files changed

+4
-17
lines changed

6 files changed

+4
-17
lines changed

absl/base/config.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
274274
#define ABSL_HAVE_STD_IS_TRIVIALLY_COPYABLE 1
275275
#endif
276276

277-
278277
// ABSL_HAVE_THREAD_LOCAL
279278
//
280279
// DEPRECATED - `thread_local` is available on all supported platforms.
@@ -813,10 +812,12 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
813812

814813
// ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
815814
//
816-
// Class template argument deduction is a language feature added in C++17.
815+
// Deprecated: always defined to 1.
816+
// Class template argument deduction is a language feature added in C++17,
817+
// which means all versions of C++ supported by Abseil have it.
817818
#ifdef ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
818819
#error "ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION cannot be directly set."
819-
#elif defined(__cpp_deduction_guides)
820+
#else
820821
#define ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION 1
821822
#endif
822823

absl/base/no_destructor.h

-2
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,10 @@ class NoDestructor {
199199
impl_;
200200
};
201201

202-
#ifdef ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
203202
// Provide 'Class Template Argument Deduction': the type of NoDestructor's T
204203
// will be the same type as the argument passed to NoDestructor's constructor.
205204
template <typename T>
206205
NoDestructor(T) -> NoDestructor<T>;
207-
#endif // ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
208206

209207
ABSL_NAMESPACE_END
210208
} // namespace absl

absl/base/no_destructor_test.cc

-4
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,10 @@ TEST(NoDestructorTest, StaticPattern) {
196196
EXPECT_EQ(0, Int()); // should get zero-initialized
197197
}
198198

199-
#ifdef ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
200-
// This would fail to compile if Class Template Argument Deduction was not
201-
// provided for absl::NoDestructor.
202199
TEST(NoDestructorTest, ClassTemplateArgumentDeduction) {
203200
absl::NoDestructor i(1);
204201
static_assert(std::is_same<decltype(i), absl::NoDestructor<int>>::value,
205202
"Expected deduced type to be int.");
206203
}
207-
#endif
208204

209205
} // namespace

absl/cleanup/cleanup.h

-2
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,8 @@ class ABSL_MUST_USE_RESULT Cleanup final {
115115
// `absl::Cleanup c = /* callback */;`
116116
//
117117
// C++17 type deduction API for creating an instance of `absl::Cleanup`
118-
#if defined(ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION)
119118
template <typename Callback>
120119
Cleanup(Callback callback) -> Cleanup<cleanup_internal::Tag, Callback>;
121-
#endif // defined(ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION)
122120

123121
// `auto c = absl::MakeCleanup(/* callback */);`
124122
//

absl/cleanup/cleanup_test.cc

-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ TYPED_TEST(CleanupTest, FactoryProducesCorrectType) {
116116
}
117117
}
118118

119-
#if defined(ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION)
120119
TYPED_TEST(CleanupTest, CTADProducesCorrectType) {
121120
{
122121
auto callback = TypeParam::AsCallback([] {});
@@ -186,7 +185,6 @@ TYPED_TEST(CleanupTest, FactoryAndCTADProduceSameType) {
186185
IsSame<decltype(factory_cleanup), decltype(deduction_cleanup)>(), "");
187186
}
188187
}
189-
#endif // defined(ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION)
190188

191189
TYPED_TEST(CleanupTest, BasicUsage) {
192190
bool called = false;

absl/log/internal/structured.h

-4
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ class ABSL_MUST_USE_RESULT AsStructuredValueImpl final {
139139
}
140140
};
141141

142-
#ifdef ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
143-
144142
// Template deduction guide so `AsStructuredValueImpl(42, data)` works
145143
// without specifying the template type.
146144
template <typename T>
@@ -155,8 +153,6 @@ AsStructuredValueImpl(
155153
typename AsStructuredValueImpl<T>::ValueFormatter value_formatter)
156154
-> AsStructuredValueImpl<T>;
157155

158-
#endif // ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
159-
160156
} // namespace log_internal
161157
ABSL_NAMESPACE_END
162158
} // namespace absl

0 commit comments

Comments
 (0)