Export of internal Abseil changes
-- a7e789be4687681b98060fddbf8bd1c64a8f5908 by Abseil Team <absl-team@google.com>: Support C++20 erase_if API in btree. See the reference here: https://en.cppreference.com/w/cpp/container/set/erase_if. PiperOrigin-RevId: 286235196 -- 952dd2fdd8435dd293e2186c97e14ef3f29a1aa6 by Derek Mauro <dmauro@google.com>: Avoids accessing an out-of-bounds value during flag parsing PiperOrigin-RevId: 286206167 -- ba24591ade579fc4446a09bb3f23bf3602908c04 by Abseil Team <absl-team@google.com>: Change null term* (and nul term*) to NUL-term* in comments. PiperOrigin-RevId: 286066376 -- d770baecf36f3d7a8214ca2033d90696ba353d00 by Andy Soffer <asoffer@google.com>: cmake: Fix x86_64 check on Windows for random copts Import of https://github.com/abseil/abseil-cpp/pull/518 PiperOrigin-RevId: 286056395 -- 9ed007e284ecf6ec79547437dbed9ce3023204b9 by Greg Falcon <gfalcon@google.com>: Manual re-import of CCTZ from GitHub. filegroup() moved as a side effect of an internal change. PiperOrigin-RevId: 286015866 -- 25441cc5cb7ee906177f8dac0dcd524df0e6e305 by Derek Mauro <dmauro@google.com>: Fix implicit cycle in debugging build rules due to .inc files PiperOrigin-RevId: 285873346 GitOrigin-RevId: a7e789be4687681b98060fddbf8bd1c64a8f5908 Change-Id: Idef8cce4e723fccae6bdd749e94e11e655908214
This commit is contained in:
parent
bf86cfe165
commit
2923513914
11 changed files with 124 additions and 26 deletions
|
@ -412,6 +412,20 @@ void swap(btree_map<K, V, C, A> &x, btree_map<K, V, C, A> &y) {
|
||||||
return x.swap(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
|
// absl::btree_multimap
|
||||||
//
|
//
|
||||||
// An `absl::btree_multimap<K, V>` is an ordered associative container of
|
// 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);
|
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
|
ABSL_NAMESPACE_END
|
||||||
} // namespace absl
|
} // namespace absl
|
||||||
|
|
||||||
|
|
|
@ -360,6 +360,20 @@ void swap(btree_set<K, C, A> &x, btree_set<K, C, A> &y) {
|
||||||
return x.swap(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<>
|
// absl::btree_multiset<>
|
||||||
//
|
//
|
||||||
// An `absl::btree_multiset<K>` is an ordered associative container of
|
// 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);
|
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
|
ABSL_NAMESPACE_END
|
||||||
} // namespace absl
|
} // namespace absl
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@ using ::absl::test_internal::InstanceTracker;
|
||||||
using ::absl::test_internal::MovableOnlyInstance;
|
using ::absl::test_internal::MovableOnlyInstance;
|
||||||
using ::testing::ElementsAre;
|
using ::testing::ElementsAre;
|
||||||
using ::testing::ElementsAreArray;
|
using ::testing::ElementsAreArray;
|
||||||
|
using ::testing::IsEmpty;
|
||||||
using ::testing::Pair;
|
using ::testing::Pair;
|
||||||
|
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
|
@ -2303,6 +2304,47 @@ TEST(Btree, EmptyTree) {
|
||||||
EXPECT_GT(s.max_size(), 0);
|
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
|
||||||
} // namespace container_internal
|
} // namespace container_internal
|
||||||
ABSL_NAMESPACE_END
|
ABSL_NAMESPACE_END
|
||||||
|
|
|
@ -5,7 +5,7 @@ set(ABSL_LSAN_LINKOPTS "")
|
||||||
set(ABSL_HAVE_LSAN OFF)
|
set(ABSL_HAVE_LSAN OFF)
|
||||||
set(ABSL_DEFAULT_LINKOPTS "")
|
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)
|
if (MSVC)
|
||||||
set(ABSL_RANDOM_RANDEN_COPTS "${ABSL_RANDOM_HWAES_MSVC_X64_FLAGS}")
|
set(ABSL_RANDOM_RANDEN_COPTS "${ABSL_RANDOM_HWAES_MSVC_X64_FLAGS}")
|
||||||
else()
|
else()
|
||||||
|
|
|
@ -31,6 +31,14 @@ licenses(["notice"]) # Apache 2.0
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "stacktrace",
|
name = "stacktrace",
|
||||||
srcs = [
|
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",
|
"stacktrace.cc",
|
||||||
],
|
],
|
||||||
hdrs = ["stacktrace.h"],
|
hdrs = ["stacktrace.h"],
|
||||||
|
@ -158,14 +166,6 @@ cc_library(
|
||||||
hdrs = [
|
hdrs = [
|
||||||
"internal/address_is_readable.h",
|
"internal/address_is_readable.h",
|
||||||
"internal/elf_mem_image.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",
|
"internal/vdso_support.h",
|
||||||
],
|
],
|
||||||
copts = ABSL_DEFAULT_COPTS,
|
copts = ABSL_DEFAULT_COPTS,
|
||||||
|
|
|
@ -19,6 +19,14 @@ absl_cc_library(
|
||||||
stacktrace
|
stacktrace
|
||||||
HDRS
|
HDRS
|
||||||
"stacktrace.h"
|
"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
|
SRCS
|
||||||
"stacktrace.cc"
|
"stacktrace.cc"
|
||||||
COPTS
|
COPTS
|
||||||
|
@ -137,14 +145,6 @@ absl_cc_library(
|
||||||
HDRS
|
HDRS
|
||||||
"internal/address_is_readable.h"
|
"internal/address_is_readable.h"
|
||||||
"internal/elf_mem_image.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"
|
"internal/vdso_support.h"
|
||||||
SRCS
|
SRCS
|
||||||
"internal/address_is_readable.cc"
|
"internal/address_is_readable.cc"
|
||||||
|
|
|
@ -525,7 +525,7 @@ std::tuple<bool, absl::string_view> DeduceFlagValue(const CommandLineFlag& flag,
|
||||||
// --my_string_var --foo=bar
|
// --my_string_var --foo=bar
|
||||||
// We look for a flag of std::string type, whose value begins with a
|
// We look for a flag of std::string type, whose value begins with a
|
||||||
// dash and corresponds to known flag or standalone --.
|
// 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)));
|
auto maybe_flag_name = std::get<0>(SplitNameAndValue(value.substr(1)));
|
||||||
|
|
||||||
if (maybe_flag_name.empty() ||
|
if (maybe_flag_name.empty() ||
|
||||||
|
|
|
@ -282,7 +282,7 @@ ConvertResult<Conv::s | Conv::p> FormatConvertImpl(const char *v,
|
||||||
} else if (conv.precision() < 0) {
|
} else if (conv.precision() < 0) {
|
||||||
len = std::strlen(v);
|
len = std::strlen(v);
|
||||||
} else {
|
} 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;
|
len = std::find(v, v + conv.precision(), '\0') - v;
|
||||||
}
|
}
|
||||||
return {ConvertStringArg(string_view(v, len), conv, sink)};
|
return {ConvertStringArg(string_view(v, len), conv, sink)};
|
||||||
|
|
|
@ -154,7 +154,7 @@ TEST_F(FormatConvertTest, StringPrecision) {
|
||||||
UntypedFormatSpecImpl format("%.1s");
|
UntypedFormatSpecImpl format("%.1s");
|
||||||
EXPECT_EQ("a", FormatPack(format, {FormatArgImpl(p)}));
|
EXPECT_EQ("a", FormatPack(format, {FormatArgImpl(p)}));
|
||||||
|
|
||||||
// We cap at the nul terminator.
|
// We cap at the NUL-terminator.
|
||||||
p = "ABC";
|
p = "ABC";
|
||||||
UntypedFormatSpecImpl format2("%.10s");
|
UntypedFormatSpecImpl format2("%.10s");
|
||||||
EXPECT_EQ("ABC", FormatPack(format2, {FormatArgImpl(p)}));
|
EXPECT_EQ("ABC", FormatPack(format2, {FormatArgImpl(p)}));
|
||||||
|
|
|
@ -402,7 +402,7 @@ int FPrintF(std::FILE* output, const FormatSpec<Args...>& format,
|
||||||
// type-safe); prefer `absl::SNPrintF()` over `std::snprintf()`.
|
// type-safe); prefer `absl::SNPrintF()` over `std::snprintf()`.
|
||||||
//
|
//
|
||||||
// In particular, a successful call to `absl::SNPrintF()` writes at most `size`
|
// 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
|
// 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`
|
// not occur. In the event of an error, a negative value is returned and `errno`
|
||||||
// is set.
|
// is set.
|
||||||
|
|
|
@ -18,6 +18,11 @@ package(features = ["-parse_headers"])
|
||||||
|
|
||||||
licenses(["notice"]) # Apache License
|
licenses(["notice"]) # Apache License
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "zoneinfo",
|
||||||
|
srcs = glob(["testdata/zoneinfo/**"]),
|
||||||
|
)
|
||||||
|
|
||||||
config_setting(
|
config_setting(
|
||||||
name = "osx",
|
name = "osx",
|
||||||
constraint_values = [
|
constraint_values = [
|
||||||
|
@ -159,8 +164,3 @@ cc_test(
|
||||||
### examples
|
### examples
|
||||||
|
|
||||||
### binaries
|
### binaries
|
||||||
|
|
||||||
filegroup(
|
|
||||||
name = "zoneinfo",
|
|
||||||
srcs = glob(["testdata/zoneinfo/**"]),
|
|
||||||
)
|
|
||||||
|
|
Loading…
Reference in a new issue