about summary refs log tree commit diff
path: root/absl
diff options
context:
space:
mode:
Diffstat (limited to 'absl')
-rw-r--r--absl/container/btree_map.h28
-rw-r--r--absl/container/btree_set.h28
-rw-r--r--absl/container/btree_test.cc42
-rw-r--r--absl/copts/AbseilConfigureCopts.cmake2
-rw-r--r--absl/debugging/BUILD.bazel16
-rw-r--r--absl/debugging/CMakeLists.txt16
-rw-r--r--absl/flags/parse.cc2
-rw-r--r--absl/strings/internal/str_format/arg.cc2
-rw-r--r--absl/strings/internal/str_format/convert_test.cc2
-rw-r--r--absl/strings/str_format.h2
-rw-r--r--absl/time/internal/cctz/BUILD.bazel10
11 files changed, 124 insertions, 26 deletions
diff --git a/absl/container/btree_map.h b/absl/container/btree_map.h
index 470e3197084c..cbfcb58c4129 100644
--- a/absl/container/btree_map.h
+++ b/absl/container/btree_map.h
@@ -412,6 +412,20 @@ void swap(btree_map<K, V, C, A> &x, btree_map<K, V, C, A> &y) {
   return x.swap(y);
 }
 
+// absl::erase_if(absl::btree_map<>, Pred)
+//
+// Erases all elements that satisfy the predicate pred from the container.
+template <typename K, typename V, typename C, typename A, typename Pred>
+void erase_if(btree_map<K, V, C, A> &map, Pred pred) {
+  for (auto it = map.begin(); it != map.end();) {
+    if (pred(*it)) {
+      it = map.erase(it);
+    } else {
+      ++it;
+    }
+  }
+}
+
 // absl::btree_multimap
 //
 // An `absl::btree_multimap<K, V>` is an ordered associative container of
@@ -701,6 +715,20 @@ void swap(btree_multimap<K, V, C, A> &x, btree_multimap<K, V, C, A> &y) {
   return x.swap(y);
 }
 
+// absl::erase_if(absl::btree_multimap<>, Pred)
+//
+// Erases all elements that satisfy the predicate pred from the container.
+template <typename K, typename V, typename C, typename A, typename Pred>
+void erase_if(btree_multimap<K, V, C, A> &map, Pred pred) {
+  for (auto it = map.begin(); it != map.end();) {
+    if (pred(*it)) {
+      it = map.erase(it);
+    } else {
+      ++it;
+    }
+  }
+}
+
 ABSL_NAMESPACE_END
 }  // namespace absl
 
diff --git a/absl/container/btree_set.h b/absl/container/btree_set.h
index 2a4d0aceb354..127fb940d40e 100644
--- a/absl/container/btree_set.h
+++ b/absl/container/btree_set.h
@@ -360,6 +360,20 @@ void swap(btree_set<K, C, A> &x, btree_set<K, C, A> &y) {
   return x.swap(y);
 }
 
+// absl::erase_if(absl::btree_set<>, Pred)
+//
+// Erases all elements that satisfy the predicate pred from the container.
+template <typename K, typename C, typename A, typename Pred>
+void erase_if(btree_set<K, C, A> &set, Pred pred) {
+  for (auto it = set.begin(); it != set.end();) {
+    if (pred(*it)) {
+      it = set.erase(it);
+    } else {
+      ++it;
+    }
+  }
+}
+
 // absl::btree_multiset<>
 //
 // An `absl::btree_multiset<K>` is an ordered associative container of
@@ -649,6 +663,20 @@ void swap(btree_multiset<K, C, A> &x, btree_multiset<K, C, A> &y) {
   return x.swap(y);
 }
 
+// absl::erase_if(absl::btree_multiset<>, Pred)
+//
+// Erases all elements that satisfy the predicate pred from the container.
+template <typename K, typename C, typename A, typename Pred>
+void erase_if(btree_multiset<K, C, A> &set, Pred pred) {
+  for (auto it = set.begin(); it != set.end();) {
+    if (pred(*it)) {
+      it = set.erase(it);
+    } else {
+      ++it;
+    }
+  }
+}
+
 ABSL_NAMESPACE_END
 }  // namespace absl
 
diff --git a/absl/container/btree_test.cc b/absl/container/btree_test.cc
index f8aadd62ad75..8692b9c2b9d7 100644
--- a/absl/container/btree_test.cc
+++ b/absl/container/btree_test.cc
@@ -51,6 +51,7 @@ using ::absl::test_internal::InstanceTracker;
 using ::absl::test_internal::MovableOnlyInstance;
 using ::testing::ElementsAre;
 using ::testing::ElementsAreArray;
+using ::testing::IsEmpty;
 using ::testing::Pair;
 
 template <typename T, typename U>
@@ -2303,6 +2304,47 @@ TEST(Btree, EmptyTree) {
   EXPECT_GT(s.max_size(), 0);
 }
 
+bool IsEven(int k) { return k % 2 == 0; }
+
+TEST(Btree, EraseIf) {
+  // Test that erase_if works with all the container types and supports lambdas.
+  {
+    absl::btree_set<int> s = {1, 3, 5, 6, 100};
+    erase_if(s, [](int k) { return k > 3; });
+    EXPECT_THAT(s, ElementsAre(1, 3));
+  }
+  {
+    absl::btree_multiset<int> s = {1, 3, 3, 5, 6, 6, 100};
+    erase_if(s, [](int k) { return k <= 3; });
+    EXPECT_THAT(s, ElementsAre(5, 6, 6, 100));
+  }
+  {
+    absl::btree_map<int, int> m = {{1, 1}, {3, 3}, {6, 6}, {100, 100}};
+    erase_if(m, [](std::pair<const int, int> kv) { return kv.first > 3; });
+    EXPECT_THAT(m, ElementsAre(Pair(1, 1), Pair(3, 3)));
+  }
+  {
+    absl::btree_multimap<int, int> m = {{1, 1}, {3, 3}, {3, 6},
+                                        {6, 6}, {6, 7}, {100, 6}};
+    erase_if(m, [](std::pair<const int, int> kv) { return kv.second == 6; });
+    EXPECT_THAT(m, ElementsAre(Pair(1, 1), Pair(3, 3), Pair(6, 7)));
+  }
+  // Test that erasing all elements from a large set works and test support for
+  // function pointers.
+  {
+    absl::btree_set<int> s;
+    for (int i = 0; i < 1000; ++i) s.insert(2 * i);
+    erase_if(s, IsEven);
+    EXPECT_THAT(s, IsEmpty());
+  }
+  // Test that erase_if supports other format of function pointers.
+  {
+    absl::btree_set<int> s = {1, 3, 5, 6, 100};
+    erase_if(s, &IsEven);
+    EXPECT_THAT(s, ElementsAre(1, 3, 5));
+  }
+}
+
 }  // namespace
 }  // namespace container_internal
 ABSL_NAMESPACE_END
diff --git a/absl/copts/AbseilConfigureCopts.cmake b/absl/copts/AbseilConfigureCopts.cmake
index b442646948a2..52e89ae580a3 100644
--- a/absl/copts/AbseilConfigureCopts.cmake
+++ b/absl/copts/AbseilConfigureCopts.cmake
@@ -5,7 +5,7 @@ set(ABSL_LSAN_LINKOPTS "")
 set(ABSL_HAVE_LSAN OFF)
 set(ABSL_DEFAULT_LINKOPTS "")
 
-if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
+if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64")
   if (MSVC)
     set(ABSL_RANDOM_RANDEN_COPTS "${ABSL_RANDOM_HWAES_MSVC_X64_FLAGS}")
   else()
diff --git a/absl/debugging/BUILD.bazel b/absl/debugging/BUILD.bazel
index 32cacefde3df..a01408910ac4 100644
--- a/absl/debugging/BUILD.bazel
+++ b/absl/debugging/BUILD.bazel
@@ -31,6 +31,14 @@ licenses(["notice"])  # Apache 2.0
 cc_library(
     name = "stacktrace",
     srcs = [
+        "internal/stacktrace_aarch64-inl.inc",
+        "internal/stacktrace_arm-inl.inc",
+        "internal/stacktrace_config.h",
+        "internal/stacktrace_generic-inl.inc",
+        "internal/stacktrace_powerpc-inl.inc",
+        "internal/stacktrace_unimplemented-inl.inc",
+        "internal/stacktrace_win32-inl.inc",
+        "internal/stacktrace_x86-inl.inc",
         "stacktrace.cc",
     ],
     hdrs = ["stacktrace.h"],
@@ -158,14 +166,6 @@ cc_library(
     hdrs = [
         "internal/address_is_readable.h",
         "internal/elf_mem_image.h",
-        "internal/stacktrace_aarch64-inl.inc",
-        "internal/stacktrace_arm-inl.inc",
-        "internal/stacktrace_config.h",
-        "internal/stacktrace_generic-inl.inc",
-        "internal/stacktrace_powerpc-inl.inc",
-        "internal/stacktrace_unimplemented-inl.inc",
-        "internal/stacktrace_win32-inl.inc",
-        "internal/stacktrace_x86-inl.inc",
         "internal/vdso_support.h",
     ],
     copts = ABSL_DEFAULT_COPTS,
diff --git a/absl/debugging/CMakeLists.txt b/absl/debugging/CMakeLists.txt
index ef9e71fc0481..66886c7a0949 100644
--- a/absl/debugging/CMakeLists.txt
+++ b/absl/debugging/CMakeLists.txt
@@ -19,6 +19,14 @@ absl_cc_library(
     stacktrace
   HDRS
     "stacktrace.h"
+    "internal/stacktrace_aarch64-inl.inc"
+    "internal/stacktrace_arm-inl.inc"
+    "internal/stacktrace_config.h"
+    "internal/stacktrace_generic-inl.inc"
+    "internal/stacktrace_powerpc-inl.inc"
+    "internal/stacktrace_unimplemented-inl.inc"
+    "internal/stacktrace_win32-inl.inc"
+    "internal/stacktrace_x86-inl.inc"
   SRCS
     "stacktrace.cc"
   COPTS
@@ -137,14 +145,6 @@ absl_cc_library(
   HDRS
     "internal/address_is_readable.h"
     "internal/elf_mem_image.h"
-    "internal/stacktrace_aarch64-inl.inc"
-    "internal/stacktrace_arm-inl.inc"
-    "internal/stacktrace_config.h"
-    "internal/stacktrace_generic-inl.inc"
-    "internal/stacktrace_powerpc-inl.inc"
-    "internal/stacktrace_unimplemented-inl.inc"
-    "internal/stacktrace_win32-inl.inc"
-    "internal/stacktrace_x86-inl.inc"
     "internal/vdso_support.h"
   SRCS
     "internal/address_is_readable.cc"
diff --git a/absl/flags/parse.cc b/absl/flags/parse.cc
index 5a56a35625df..2f07725f5614 100644
--- a/absl/flags/parse.cc
+++ b/absl/flags/parse.cc
@@ -525,7 +525,7 @@ std::tuple<bool, absl::string_view> DeduceFlagValue(const CommandLineFlag& flag,
     // --my_string_var --foo=bar
     // We look for a flag of std::string type, whose value begins with a
     // dash and corresponds to known flag or standalone --.
-    if (value[0] == '-' && flag.IsOfType<std::string>()) {
+    if (!value.empty() && value[0] == '-' && flag.IsOfType<std::string>()) {
       auto maybe_flag_name = std::get<0>(SplitNameAndValue(value.substr(1)));
 
       if (maybe_flag_name.empty() ||
diff --git a/absl/strings/internal/str_format/arg.cc b/absl/strings/internal/str_format/arg.cc
index 875bd99c4286..d3904124a1a9 100644
--- a/absl/strings/internal/str_format/arg.cc
+++ b/absl/strings/internal/str_format/arg.cc
@@ -282,7 +282,7 @@ ConvertResult<Conv::s | Conv::p> FormatConvertImpl(const char *v,
   } else if (conv.precision() < 0) {
     len = std::strlen(v);
   } else {
-    // If precision is set, we look for the null terminator on the valid range.
+    // If precision is set, we look for the NUL-terminator on the valid range.
     len = std::find(v, v + conv.precision(), '\0') - v;
   }
   return {ConvertStringArg(string_view(v, len), conv, sink)};
diff --git a/absl/strings/internal/str_format/convert_test.cc b/absl/strings/internal/str_format/convert_test.cc
index ca99434679cf..cbcd7caf4665 100644
--- a/absl/strings/internal/str_format/convert_test.cc
+++ b/absl/strings/internal/str_format/convert_test.cc
@@ -154,7 +154,7 @@ TEST_F(FormatConvertTest, StringPrecision) {
   UntypedFormatSpecImpl format("%.1s");
   EXPECT_EQ("a", FormatPack(format, {FormatArgImpl(p)}));
 
-  // We cap at the nul terminator.
+  // We cap at the NUL-terminator.
   p = "ABC";
   UntypedFormatSpecImpl format2("%.10s");
   EXPECT_EQ("ABC", FormatPack(format2, {FormatArgImpl(p)}));
diff --git a/absl/strings/str_format.h b/absl/strings/str_format.h
index fbbfe43d6cb7..2f9b4b2786f8 100644
--- a/absl/strings/str_format.h
+++ b/absl/strings/str_format.h
@@ -402,7 +402,7 @@ int FPrintF(std::FILE* output, const FormatSpec<Args...>& format,
 // type-safe); prefer `absl::SNPrintF()` over `std::snprintf()`.
 //
 // In particular, a successful call to `absl::SNPrintF()` writes at most `size`
-// bytes of the formatted output to `output`, including a null terminator, and
+// bytes of the formatted output to `output`, including a NUL-terminator, and
 // returns the number of bytes that would have been written if truncation did
 // not occur. In the event of an error, a negative value is returned and `errno`
 // is set.
diff --git a/absl/time/internal/cctz/BUILD.bazel b/absl/time/internal/cctz/BUILD.bazel
index 5ad0f0363907..7a53c815b99e 100644
--- a/absl/time/internal/cctz/BUILD.bazel
+++ b/absl/time/internal/cctz/BUILD.bazel
@@ -18,6 +18,11 @@ package(features = ["-parse_headers"])
 
 licenses(["notice"])  # Apache License
 
+filegroup(
+    name = "zoneinfo",
+    srcs = glob(["testdata/zoneinfo/**"]),
+)
+
 config_setting(
     name = "osx",
     constraint_values = [
@@ -159,8 +164,3 @@ cc_test(
 ### examples
 
 ### binaries
-
-filegroup(
-    name = "zoneinfo",
-    srcs = glob(["testdata/zoneinfo/**"]),
-)