Skip to content

Commit 464b5b3

Browse files
OmerMorcopybara-github
authored andcommitted
Deprecate ABSL_HAVE_STD_STRING_VIEW.
This macro is no longer necessary now that Abseil requires C++17. PiperOrigin-RevId: 755992345 Change-Id: Id1361d62d860a0ba4bdfca22e8f39d54812ef82c
1 parent 9fcfa06 commit 464b5b3

File tree

13 files changed

+19
-138
lines changed

13 files changed

+19
-138
lines changed

absl/base/config.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -530,13 +530,12 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
530530

531531
// ABSL_HAVE_STD_STRING_VIEW
532532
//
533-
// Checks whether C++17 std::string_view is available.
533+
// Deprecated: always defined to 1.
534+
// std::string_view was added in C++17, which means all versions of C++
535+
// supported by Abseil have it.
534536
#ifdef ABSL_HAVE_STD_STRING_VIEW
535537
#error "ABSL_HAVE_STD_STRING_VIEW cannot be directly set."
536-
#elif defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
537-
#define ABSL_HAVE_STD_STRING_VIEW 1
538-
#elif defined(ABSL_INTERNAL_CPLUSPLUS_LANG) && \
539-
ABSL_INTERNAL_CPLUSPLUS_LANG >= 201703L
538+
#else
540539
#define ABSL_HAVE_STD_STRING_VIEW 1
541540
#endif
542541

@@ -561,13 +560,10 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
561560
// Indicates whether absl::string_view is an alias for std::string_view.
562561
#if !defined(ABSL_OPTION_USE_STD_STRING_VIEW)
563562
#error options.h is misconfigured.
564-
#elif ABSL_OPTION_USE_STD_STRING_VIEW == 0 || \
565-
(ABSL_OPTION_USE_STD_STRING_VIEW == 2 && \
566-
!defined(ABSL_HAVE_STD_STRING_VIEW))
563+
#elif ABSL_OPTION_USE_STD_STRING_VIEW == 0
567564
#undef ABSL_USES_STD_STRING_VIEW
568565
#elif ABSL_OPTION_USE_STD_STRING_VIEW == 1 || \
569-
(ABSL_OPTION_USE_STD_STRING_VIEW == 2 && \
570-
defined(ABSL_HAVE_STD_STRING_VIEW))
566+
ABSL_OPTION_USE_STD_STRING_VIEW == 2
571567
#define ABSL_USES_STD_STRING_VIEW 1
572568
#else
573569
#error options.h is misconfigured.

absl/container/internal/hash_function_defaults.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include <functional>
5050
#include <memory>
5151
#include <string>
52+
#include <string_view>
5253
#include <type_traits>
5354

5455
#include "absl/base/config.h"
@@ -58,10 +59,6 @@
5859
#include "absl/strings/cord.h"
5960
#include "absl/strings/string_view.h"
6061

61-
#ifdef ABSL_HAVE_STD_STRING_VIEW
62-
#include <string_view>
63-
#endif
64-
6562
namespace absl {
6663
ABSL_NAMESPACE_BEGIN
6764
namespace container_internal {
@@ -113,8 +110,6 @@ struct HashEq<absl::string_view> : StringHashEq {};
113110
template <>
114111
struct HashEq<absl::Cord> : StringHashEq {};
115112

116-
#ifdef ABSL_HAVE_STD_STRING_VIEW
117-
118113
template <typename TChar>
119114
struct BasicStringHash {
120115
using is_transparent = void;
@@ -153,8 +148,6 @@ struct HashEq<std::u32string> : BasicStringHashEq<char32_t> {};
153148
template <>
154149
struct HashEq<std::u32string_view> : BasicStringHashEq<char32_t> {};
155150

156-
#endif // ABSL_HAVE_STD_STRING_VIEW
157-
158151
// Supports heterogeneous lookup for pointers and smart pointers.
159152
template <class T>
160153
struct HashEq<T*> {

absl/container/internal/hash_function_defaults_test.cc

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <cstddef>
1818
#include <functional>
19+
#include <string_view>
1920
#include <type_traits>
2021
#include <utility>
2122

@@ -28,10 +29,6 @@
2829
#include "absl/strings/cord_test_helpers.h"
2930
#include "absl/strings/string_view.h"
3031

31-
#ifdef ABSL_HAVE_STD_STRING_VIEW
32-
#include <string_view>
33-
#endif
34-
3532
namespace absl {
3633
ABSL_NAMESPACE_BEGIN
3734
namespace container_internal {
@@ -118,165 +115,117 @@ TYPED_TEST(HashString, Works) {
118115
}
119116

120117
TEST(BasicStringViewTest, WStringEqWorks) {
121-
#ifndef ABSL_HAVE_STD_STRING_VIEW
122-
GTEST_SKIP();
123-
#else
124118
hash_default_eq<std::wstring> eq;
125119
EXPECT_TRUE(eq(L"a", L"a"));
126120
EXPECT_TRUE(eq(L"a", std::wstring_view(L"a")));
127121
EXPECT_TRUE(eq(L"a", std::wstring(L"a")));
128122
EXPECT_FALSE(eq(L"a", L"b"));
129123
EXPECT_FALSE(eq(L"a", std::wstring_view(L"b")));
130124
EXPECT_FALSE(eq(L"a", std::wstring(L"b")));
131-
#endif
132125
}
133126

134127
TEST(BasicStringViewTest, WStringViewEqWorks) {
135-
#ifndef ABSL_HAVE_STD_STRING_VIEW
136-
GTEST_SKIP();
137-
#else
138128
hash_default_eq<std::wstring_view> eq;
139129
EXPECT_TRUE(eq(L"a", L"a"));
140130
EXPECT_TRUE(eq(L"a", std::wstring_view(L"a")));
141131
EXPECT_TRUE(eq(L"a", std::wstring(L"a")));
142132
EXPECT_FALSE(eq(L"a", L"b"));
143133
EXPECT_FALSE(eq(L"a", std::wstring_view(L"b")));
144134
EXPECT_FALSE(eq(L"a", std::wstring(L"b")));
145-
#endif
146135
}
147136

148137
TEST(BasicStringViewTest, U16StringEqWorks) {
149-
#ifndef ABSL_HAVE_STD_STRING_VIEW
150-
GTEST_SKIP();
151-
#else
152138
hash_default_eq<std::u16string> eq;
153139
EXPECT_TRUE(eq(u"a", u"a"));
154140
EXPECT_TRUE(eq(u"a", std::u16string_view(u"a")));
155141
EXPECT_TRUE(eq(u"a", std::u16string(u"a")));
156142
EXPECT_FALSE(eq(u"a", u"b"));
157143
EXPECT_FALSE(eq(u"a", std::u16string_view(u"b")));
158144
EXPECT_FALSE(eq(u"a", std::u16string(u"b")));
159-
#endif
160145
}
161146

162147
TEST(BasicStringViewTest, U16StringViewEqWorks) {
163-
#ifndef ABSL_HAVE_STD_STRING_VIEW
164-
GTEST_SKIP();
165-
#else
166148
hash_default_eq<std::u16string_view> eq;
167149
EXPECT_TRUE(eq(u"a", u"a"));
168150
EXPECT_TRUE(eq(u"a", std::u16string_view(u"a")));
169151
EXPECT_TRUE(eq(u"a", std::u16string(u"a")));
170152
EXPECT_FALSE(eq(u"a", u"b"));
171153
EXPECT_FALSE(eq(u"a", std::u16string_view(u"b")));
172154
EXPECT_FALSE(eq(u"a", std::u16string(u"b")));
173-
#endif
174155
}
175156

176157
TEST(BasicStringViewTest, U32StringEqWorks) {
177-
#ifndef ABSL_HAVE_STD_STRING_VIEW
178-
GTEST_SKIP();
179-
#else
180158
hash_default_eq<std::u32string> eq;
181159
EXPECT_TRUE(eq(U"a", U"a"));
182160
EXPECT_TRUE(eq(U"a", std::u32string_view(U"a")));
183161
EXPECT_TRUE(eq(U"a", std::u32string(U"a")));
184162
EXPECT_FALSE(eq(U"a", U"b"));
185163
EXPECT_FALSE(eq(U"a", std::u32string_view(U"b")));
186164
EXPECT_FALSE(eq(U"a", std::u32string(U"b")));
187-
#endif
188165
}
189166

190167
TEST(BasicStringViewTest, U32StringViewEqWorks) {
191-
#ifndef ABSL_HAVE_STD_STRING_VIEW
192-
GTEST_SKIP();
193-
#else
194168
hash_default_eq<std::u32string_view> eq;
195169
EXPECT_TRUE(eq(U"a", U"a"));
196170
EXPECT_TRUE(eq(U"a", std::u32string_view(U"a")));
197171
EXPECT_TRUE(eq(U"a", std::u32string(U"a")));
198172
EXPECT_FALSE(eq(U"a", U"b"));
199173
EXPECT_FALSE(eq(U"a", std::u32string_view(U"b")));
200174
EXPECT_FALSE(eq(U"a", std::u32string(U"b")));
201-
#endif
202175
}
203176

204177
TEST(BasicStringViewTest, WStringHashWorks) {
205-
#ifndef ABSL_HAVE_STD_STRING_VIEW
206-
GTEST_SKIP();
207-
#else
208178
hash_default_hash<std::wstring> hash;
209179
auto h = hash(L"a");
210180
EXPECT_EQ(h, hash(std::wstring_view(L"a")));
211181
EXPECT_EQ(h, hash(std::wstring(L"a")));
212182
EXPECT_NE(h, hash(std::wstring_view(L"b")));
213183
EXPECT_NE(h, hash(std::wstring(L"b")));
214-
#endif
215184
}
216185

217186
TEST(BasicStringViewTest, WStringViewHashWorks) {
218-
#ifndef ABSL_HAVE_STD_STRING_VIEW
219-
GTEST_SKIP();
220-
#else
221187
hash_default_hash<std::wstring_view> hash;
222188
auto h = hash(L"a");
223189
EXPECT_EQ(h, hash(std::wstring_view(L"a")));
224190
EXPECT_EQ(h, hash(std::wstring(L"a")));
225191
EXPECT_NE(h, hash(std::wstring_view(L"b")));
226192
EXPECT_NE(h, hash(std::wstring(L"b")));
227-
#endif
228193
}
229194

230195
TEST(BasicStringViewTest, U16StringHashWorks) {
231-
#ifndef ABSL_HAVE_STD_STRING_VIEW
232-
GTEST_SKIP();
233-
#else
234196
hash_default_hash<std::u16string> hash;
235197
auto h = hash(u"a");
236198
EXPECT_EQ(h, hash(std::u16string_view(u"a")));
237199
EXPECT_EQ(h, hash(std::u16string(u"a")));
238200
EXPECT_NE(h, hash(std::u16string_view(u"b")));
239201
EXPECT_NE(h, hash(std::u16string(u"b")));
240-
#endif
241202
}
242203

243204
TEST(BasicStringViewTest, U16StringViewHashWorks) {
244-
#ifndef ABSL_HAVE_STD_STRING_VIEW
245-
GTEST_SKIP();
246-
#else
247205
hash_default_hash<std::u16string_view> hash;
248206
auto h = hash(u"a");
249207
EXPECT_EQ(h, hash(std::u16string_view(u"a")));
250208
EXPECT_EQ(h, hash(std::u16string(u"a")));
251209
EXPECT_NE(h, hash(std::u16string_view(u"b")));
252210
EXPECT_NE(h, hash(std::u16string(u"b")));
253-
#endif
254211
}
255212

256213
TEST(BasicStringViewTest, U32StringHashWorks) {
257-
#ifndef ABSL_HAVE_STD_STRING_VIEW
258-
GTEST_SKIP();
259-
#else
260214
hash_default_hash<std::u32string> hash;
261215
auto h = hash(U"a");
262216
EXPECT_EQ(h, hash(std::u32string_view(U"a")));
263217
EXPECT_EQ(h, hash(std::u32string(U"a")));
264218
EXPECT_NE(h, hash(std::u32string_view(U"b")));
265219
EXPECT_NE(h, hash(std::u32string(U"b")));
266-
#endif
267220
}
268221

269222
TEST(BasicStringViewTest, U32StringViewHashWorks) {
270-
#ifndef ABSL_HAVE_STD_STRING_VIEW
271-
GTEST_SKIP();
272-
#else
273223
hash_default_hash<std::u32string_view> hash;
274224
auto h = hash(U"a");
275225
EXPECT_EQ(h, hash(std::u32string_view(U"a")));
276226
EXPECT_EQ(h, hash(std::u32string(U"a")));
277227
EXPECT_NE(h, hash(std::u32string_view(U"b")));
278228
EXPECT_NE(h, hash(std::u32string(U"b")));
279-
#endif
280229
}
281230

282231
struct NoDeleter {

absl/hash/hash_test.cc

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <ostream>
3030
#include <set>
3131
#include <string>
32+
#include <string_view>
3233
#include <tuple>
3334
#include <type_traits>
3435
#include <unordered_map>
@@ -55,10 +56,6 @@
5556
#include <filesystem> // NOLINT
5657
#endif
5758

58-
#ifdef ABSL_HAVE_STD_STRING_VIEW
59-
#include <string_view>
60-
#endif
61-
6259
namespace {
6360

6461
using ::absl::hash_test_internal::is_hashable;
@@ -495,44 +492,32 @@ TEST(HashValueTest, U32String) {
495492
}
496493

497494
TEST(HashValueTest, WStringView) {
498-
#ifndef ABSL_HAVE_STD_STRING_VIEW
499-
GTEST_SKIP();
500-
#else
501495
EXPECT_TRUE((is_hashable<std::wstring_view>::value));
502496

503497
EXPECT_TRUE(absl::VerifyTypeImplementsAbslHashCorrectly(std::make_tuple(
504498
std::wstring_view(), std::wstring_view(L"ABC"), std::wstring_view(L"ABC"),
505499
std::wstring_view(L"Some other different string_view"),
506500
std::wstring_view(L"Iñtërnâtiônàlizætiøn"))));
507-
#endif
508501
}
509502

510503
TEST(HashValueTest, U16StringView) {
511-
#ifndef ABSL_HAVE_STD_STRING_VIEW
512-
GTEST_SKIP();
513-
#else
514504
EXPECT_TRUE((is_hashable<std::u16string_view>::value));
515505

516506
EXPECT_TRUE(absl::VerifyTypeImplementsAbslHashCorrectly(
517507
std::make_tuple(std::u16string_view(), std::u16string_view(u"ABC"),
518508
std::u16string_view(u"ABC"),
519509
std::u16string_view(u"Some other different string_view"),
520510
std::u16string_view(u"Iñtërnâtiônàlizætiøn"))));
521-
#endif
522511
}
523512

524513
TEST(HashValueTest, U32StringView) {
525-
#ifndef ABSL_HAVE_STD_STRING_VIEW
526-
GTEST_SKIP();
527-
#else
528514
EXPECT_TRUE((is_hashable<std::u32string_view>::value));
529515

530516
EXPECT_TRUE(absl::VerifyTypeImplementsAbslHashCorrectly(
531517
std::make_tuple(std::u32string_view(), std::u32string_view(U"ABC"),
532518
std::u32string_view(U"ABC"),
533519
std::u32string_view(U"Some other different string_view"),
534520
std::u32string_view(U"Iñtërnâtiônàlizætiøn"))));
535-
#endif
536521
}
537522

538523
TEST(HashValueTest, StdFilesystemPath) {

absl/hash/internal/hash.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include <memory>
6666
#include <set>
6767
#include <string>
68+
#include <string_view>
6869
#include <tuple>
6970
#include <type_traits>
7071
#include <unordered_map>
@@ -92,10 +93,6 @@
9293
#include <filesystem> // NOLINT
9394
#endif
9495

95-
#ifdef ABSL_HAVE_STD_STRING_VIEW
96-
#include <string_view>
97-
#endif
98-
9996
namespace absl {
10097
ABSL_NAMESPACE_BEGIN
10198

@@ -640,8 +637,6 @@ H AbslHashValue(
640637
WeaklyMixedInteger{str.size()});
641638
}
642639

643-
#ifdef ABSL_HAVE_STD_STRING_VIEW
644-
645640
// Support std::wstring_view, std::u16string_view and std::u32string_view.
646641
template <typename Char, typename H,
647642
typename = absl::enable_if_t<std::is_same<Char, wchar_t>::value ||
@@ -653,8 +648,6 @@ H AbslHashValue(H hash_state, std::basic_string_view<Char> str) {
653648
WeaklyMixedInteger{str.size()});
654649
}
655650

656-
#endif // ABSL_HAVE_STD_STRING_VIEW
657-
658651
#if defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L && \
659652
(!defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) || \
660653
__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 130000) && \

absl/meta/type_traits.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <cstddef>
3939
#include <functional>
4040
#include <string>
41+
#include <string_view>
4142
#include <type_traits>
4243
#include <vector>
4344

@@ -48,10 +49,6 @@
4849
#include <span> // NOLINT(build/c++20)
4950
#endif
5051

51-
#ifdef ABSL_HAVE_STD_STRING_VIEW
52-
#include <string_view>
53-
#endif
54-
5552
// Defines the default alignment. `__STDCPP_DEFAULT_NEW_ALIGNMENT__` is a C++17
5653
// feature.
5754
#if defined(__STDCPP_DEFAULT_NEW_ALIGNMENT__)
@@ -507,10 +504,8 @@ template <typename T>
507504
struct IsView : std::integral_constant<bool, std::is_pointer<T>::value ||
508505
IsViewImpl<T>::value> {};
509506

510-
#ifdef ABSL_HAVE_STD_STRING_VIEW
511507
template <typename Char, typename Traits>
512508
struct IsView<std::basic_string_view<Char, Traits>> : std::true_type {};
513-
#endif
514509

515510
#ifdef __cpp_lib_span
516511
template <typename T>

0 commit comments

Comments
 (0)