Commit 9927a098 by Abseil Team Committed by vslashg

Export of internal Abseil changes

--
bddfb8bae4e569884bf8749f5368e536562f0682 by Samuel Benzaquen <sbenza@google.com>:

Forward the Status.

PiperOrigin-RevId: 333159251

--
461640476dab1726eba8d26a0c8012b5a35ba0b1 by Evan Brown <ezb@google.com>:

Avoid relying on mutable b-tree set iterators in merge(). Mutable set iterators is an API difference from std::set that we want to get rid of.

Also remove a superfluous `public` member specification in btree_container.

PiperOrigin-RevId: 333101335

--
96cf8ac6946840be17da445739c950fd237159f4 by Abseil Team <absl-team@google.com>:

Explicitly mention that FormatDuration deviates from Go for the zero duration

PiperOrigin-RevId: 333094962

--
83389040371436aab4e952211e98ffa98e24fd94 by Abseil Team <absl-team@google.com>:

Internal change.

PiperOrigin-RevId: 332862771
GitOrigin-RevId: bddfb8bae4e569884bf8749f5368e536562f0682
Change-Id: I4a47043ddbad6e700380614c75566c09d4943103
parent 7680a5f8
...@@ -55,6 +55,7 @@ using ::testing::ElementsAreArray; ...@@ -55,6 +55,7 @@ using ::testing::ElementsAreArray;
using ::testing::IsEmpty; using ::testing::IsEmpty;
using ::testing::IsNull; using ::testing::IsNull;
using ::testing::Pair; using ::testing::Pair;
using ::testing::SizeIs;
template <typename T, typename U> template <typename T, typename U>
void CheckPairEquals(const T &x, const U &y) { void CheckPairEquals(const T &x, const U &y) {
...@@ -2109,6 +2110,31 @@ TEST(Btree, MergeIntoMultiMapsWithDifferentComparators) { ...@@ -2109,6 +2110,31 @@ TEST(Btree, MergeIntoMultiMapsWithDifferentComparators) {
Pair(4, 1), Pair(4, 4), Pair(5, 5))); Pair(4, 1), Pair(4, 4), Pair(5, 5)));
} }
TEST(Btree, MergeIntoSetMovableOnly) {
absl::btree_set<MovableOnlyInstance> src;
src.insert(MovableOnlyInstance(1));
absl::btree_multiset<MovableOnlyInstance> dst1;
dst1.insert(MovableOnlyInstance(2));
absl::btree_set<MovableOnlyInstance> dst2;
// Test merge into multiset.
dst1.merge(src);
EXPECT_TRUE(src.empty());
// ElementsAre/ElementsAreArray don't work with move-only types.
ASSERT_THAT(dst1, SizeIs(2));
EXPECT_EQ(*dst1.begin(), MovableOnlyInstance(1));
EXPECT_EQ(*std::next(dst1.begin()), MovableOnlyInstance(2));
// Test merge into set.
dst2.merge(dst1);
EXPECT_TRUE(dst1.empty());
ASSERT_THAT(dst2, SizeIs(2));
EXPECT_EQ(*dst2.begin(), MovableOnlyInstance(1));
EXPECT_EQ(*std::next(dst2.begin()), MovableOnlyInstance(2));
}
struct KeyCompareToWeakOrdering { struct KeyCompareToWeakOrdering {
template <typename T> template <typename T>
absl::weak_ordering operator()(const T &a, const T &b) const { absl::weak_ordering operator()(const T &a, const T &b) const {
......
...@@ -151,7 +151,6 @@ class btree_container { ...@@ -151,7 +151,6 @@ class btree_container {
return extract(iterator(position)); return extract(iterator(position));
} }
public:
// Utility routines. // Utility routines.
void clear() { tree_.clear(); } void clear() { tree_.clear(); }
void swap(btree_container &other) { tree_.swap(other.tree_); } void swap(btree_container &other) { tree_.swap(other.tree_); }
...@@ -344,7 +343,7 @@ class btree_set_container : public btree_container<Tree> { ...@@ -344,7 +343,7 @@ class btree_set_container : public btree_container<Tree> {
int> = 0> int> = 0>
void merge(btree_container<T> &src) { // NOLINT void merge(btree_container<T> &src) { // NOLINT
for (auto src_it = src.begin(); src_it != src.end();) { for (auto src_it = src.begin(); src_it != src.end();) {
if (insert(std::move(*src_it)).second) { if (insert(std::move(params_type::element(src_it.slot()))).second) {
src_it = src.erase(src_it); src_it = src.erase(src_it);
} else { } else {
++src_it; ++src_it;
...@@ -627,8 +626,9 @@ class btree_multiset_container : public btree_container<Tree> { ...@@ -627,8 +626,9 @@ class btree_multiset_container : public btree_container<Tree> {
typename T::params_type::is_map_container>>::value, typename T::params_type::is_map_container>>::value,
int> = 0> int> = 0>
void merge(btree_container<T> &src) { // NOLINT void merge(btree_container<T> &src) { // NOLINT
insert(std::make_move_iterator(src.begin()), for (auto src_it = src.begin(), end = src.end(); src_it != end; ++src_it) {
std::make_move_iterator(src.end())); insert(std::move(params_type::element(src_it.slot())));
}
src.clear(); src.clear();
} }
......
...@@ -114,7 +114,6 @@ cc_library( ...@@ -114,7 +114,6 @@ cc_library(
], ],
copts = ABSL_DEFAULT_COPTS, copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS, linkopts = ABSL_DEFAULT_LINKOPTS,
visibility = ["//visibility:private"],
deps = [ deps = [
"//absl/base:config", "//absl/base:config",
"//absl/base:fast_type_id", "//absl/base:fast_type_id",
......
...@@ -215,7 +215,7 @@ class StatusOrData { ...@@ -215,7 +215,7 @@ class StatusOrData {
template <typename U, template <typename U,
absl::enable_if_t<std::is_constructible<absl::Status, U&&>::value, absl::enable_if_t<std::is_constructible<absl::Status, U&&>::value,
int> = 0> int> = 0>
explicit StatusOrData(U&& v) : status_(v) { explicit StatusOrData(U&& v) : status_(std::forward<U>(v)) {
EnsureNotOk(); EnsureNotOk();
} }
......
...@@ -292,6 +292,17 @@ TEST(StatusOr, TestDefaultCtor) { ...@@ -292,6 +292,17 @@ TEST(StatusOr, TestDefaultCtor) {
EXPECT_EQ(thing.status().code(), absl::StatusCode::kUnknown); EXPECT_EQ(thing.status().code(), absl::StatusCode::kUnknown);
} }
TEST(StatusOr, StatusCtorForwards) {
absl::Status status(absl::StatusCode::kInternal, "Some error");
EXPECT_EQ(absl::StatusOr<int>(status).status().message(), "Some error");
EXPECT_EQ(status.message(), "Some error");
EXPECT_EQ(absl::StatusOr<int>(std::move(status)).status().message(),
"Some error");
EXPECT_NE(status.message(), "Some error");
}
// Define `EXPECT_DEATH_OR_THROW` to test the behavior of `StatusOr::value`, // Define `EXPECT_DEATH_OR_THROW` to test the behavior of `StatusOr::value`,
// which either throws `BadStatusOrAccess` or `LOG(FATAL)` based on whether // which either throws `BadStatusOrAccess` or `LOG(FATAL)` based on whether
// exceptions are enabled. // exceptions are enabled.
......
...@@ -763,7 +763,8 @@ void AppendNumberUnit(std::string* out, double n, DisplayUnit unit) { ...@@ -763,7 +763,8 @@ void AppendNumberUnit(std::string* out, double n, DisplayUnit unit) {
// form "72h3m0.5s". Leading zero units are omitted. As a special // form "72h3m0.5s". Leading zero units are omitted. As a special
// case, durations less than one second format use a smaller unit // case, durations less than one second format use a smaller unit
// (milli-, micro-, or nanoseconds) to ensure that the leading digit // (milli-, micro-, or nanoseconds) to ensure that the leading digit
// is non-zero. The zero duration formats as 0, with no unit. // is non-zero.
// Unlike Go, we format the zero duration as 0, with no unit.
std::string FormatDuration(Duration d) { std::string FormatDuration(Duration d) {
const Duration min_duration = Seconds(kint64min); const Duration min_duration = Seconds(kint64min);
if (d == min_duration) { if (d == min_duration) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment