From 831e57a483cb80100888e9f9722710c0b6afe6d7 Mon Sep 17 00:00:00 2001 From: Evan Brown Date: Wed, 21 Feb 2024 11:06:19 -0800 Subject: Change find_or_prepare_insert to return std::pair to match return type of insert. PiperOrigin-RevId: 609058024 Change-Id: I2f7cc2daf862e7e2d23acd6dd3fe85cb1945d5f0 --- absl/container/internal/raw_hash_map.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'absl/container/internal/raw_hash_map.h') diff --git a/absl/container/internal/raw_hash_map.h b/absl/container/internal/raw_hash_map.h index 97182bc7..64dcd3d4 100644 --- a/absl/container/internal/raw_hash_map.h +++ b/absl/container/internal/raw_hash_map.h @@ -201,8 +201,8 @@ class raw_hash_map : public raw_hash_set { if (res.second) this->emplace_at(res.first, std::forward(k), std::forward(v)); else - Policy::value(&*this->iterator_at(res.first)) = std::forward(v); - return {this->iterator_at(res.first), res.second}; + Policy::value(&*res.first) = std::forward(v); + return res; } template @@ -213,7 +213,7 @@ class raw_hash_map : public raw_hash_set { this->emplace_at(res.first, std::piecewise_construct, std::forward_as_tuple(std::forward(k)), std::forward_as_tuple(std::forward(args)...)); - return {this->iterator_at(res.first), res.second}; + return res; } }; -- cgit v1.2.3 From eef325b1d102aa4cbf1dbd865493ea0757222f3f Mon Sep 17 00:00:00 2001 From: Evan Brown Date: Fri, 23 Feb 2024 11:33:08 -0800 Subject: Add braces for conditional statements in raw_hash_map functions. The current version violates the Google C++ style guide - see https://google.github.io/styleguide/cppguide.html#Formatting_Looping_Branching. This code does not fit into the historical exception that "the curly braces for the controlled statement or the line breaks inside the curly braces may be omitted if as a result the entire statement appears on either a single line (in which case there is a space between the closing parenthesis and the controlled statement) or on two lines (in which case there is a line break after the closing parenthesis and there are no braces)." PiperOrigin-RevId: 609789188 Change-Id: Id7ae9596e454dac5581d19939564c07670077f92 --- absl/container/internal/raw_hash_map.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'absl/container/internal/raw_hash_map.h') diff --git a/absl/container/internal/raw_hash_map.h b/absl/container/internal/raw_hash_map.h index 64dcd3d4..464bf23b 100644 --- a/absl/container/internal/raw_hash_map.h +++ b/absl/container/internal/raw_hash_map.h @@ -198,10 +198,11 @@ class raw_hash_map : public raw_hash_set { std::pair insert_or_assign_impl(K&& k, V&& v) ABSL_ATTRIBUTE_LIFETIME_BOUND { auto res = this->find_or_prepare_insert(k); - if (res.second) + if (res.second) { this->emplace_at(res.first, std::forward(k), std::forward(v)); - else + } else { Policy::value(&*res.first) = std::forward(v); + } return res; } @@ -209,10 +210,11 @@ class raw_hash_map : public raw_hash_set { std::pair try_emplace_impl(K&& k, Args&&... args) ABSL_ATTRIBUTE_LIFETIME_BOUND { auto res = this->find_or_prepare_insert(k); - if (res.second) + if (res.second) { this->emplace_at(res.first, std::piecewise_construct, std::forward_as_tuple(std::forward(k)), std::forward_as_tuple(std::forward(args)...)); + } return res; } }; -- cgit v1.2.3