Export of internal Abseil changes.

--
6fca451d74e509671f0996e15ea05008f73c9957 by Eric Fiselier <ericwf@google.com>:

Support vector<bool>::reference and ::const_reference
in absl::Substitute.

PiperOrigin-RevId: 248524270

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

Clarify that a static `SpinLock` using the `LinkerInitialized` constructor is
initialized in non-cooperative mode.

PiperOrigin-RevId: 248386381
GitOrigin-RevId: 6fca451d74e509671f0996e15ea05008f73c9957
Change-Id: I13d54c2034695e7677170cdc7b86384b7d7d9cb5
This commit is contained in:
Abseil Team 2019-05-16 07:40:15 -07:00 committed by Andy Soffer
parent fa00c32107
commit daf381e853
3 changed files with 29 additions and 2 deletions

View file

@ -57,8 +57,10 @@ class LOCKABLE SpinLock {
// //
// static SpinLock lock(base_internal::kLinkerInitialized); // static SpinLock lock(base_internal::kLinkerInitialized);
// //
// When intialized using this constructor, we depend on the fact // When initialized using this constructor, we depend on the fact
// that the linker has already initialized the memory appropriately. // that the linker has already initialized the memory appropriately. The lock
// is initialized in non-cooperative mode.
//
// A SpinLock constructed like this can be freely used from global // A SpinLock constructed like this can be freely used from global
// initializers without worrying about the order in which global // initializers without worrying about the order in which global
// initializers run. // initializers run.

View file

@ -69,6 +69,8 @@
#include <cstring> #include <cstring>
#include <string> #include <string>
#include <type_traits>
#include <vector>
#include "absl/base/macros.h" #include "absl/base/macros.h"
#include "absl/base/port.h" #include "absl/base/port.h"
@ -151,6 +153,17 @@ class Arg {
Arg(Hex hex); // NOLINT(runtime/explicit) Arg(Hex hex); // NOLINT(runtime/explicit)
Arg(Dec dec); // NOLINT(runtime/explicit) Arg(Dec dec); // NOLINT(runtime/explicit)
// vector<bool>::reference and const_reference require special help to
// convert to `AlphaNum` because it requires two user defined conversions.
template <typename T,
absl::enable_if_t<
std::is_class<T>::value &&
(std::is_same<T, std::vector<bool>::reference>::value ||
std::is_same<T, std::vector<bool>::const_reference>::value)>* =
nullptr>
Arg(T value) // NOLINT(google-explicit-constructor)
: Arg(static_cast<bool>(value)) {}
// `void*` values, with the exception of `char*`, are printed as // `void*` values, with the exception of `char*`, are printed as
// "0x<hex value>". However, in the case of `nullptr`, "NULL" is printed. // "0x<hex value>". However, in the case of `nullptr`, "NULL" is printed.
Arg(const void* value); // NOLINT(runtime/explicit) Arg(const void* value); // NOLINT(runtime/explicit)

View file

@ -15,6 +15,7 @@
#include "absl/strings/substitute.h" #include "absl/strings/substitute.h"
#include <cstdint> #include <cstdint>
#include <vector>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
@ -172,6 +173,17 @@ TEST(SubstituteTest, SubstituteAndAppend) {
EXPECT_EQ("a b c d e f g h i j", str); EXPECT_EQ("a b c d e f g h i j", str);
} }
TEST(SubstituteTest, VectorBoolRef) {
std::vector<bool> v = {true, false};
const auto& cv = v;
EXPECT_EQ("true false true false",
absl::Substitute("$0 $1 $2 $3", v[0], v[1], cv[0], cv[1]));
std::string str = "Logic be like: ";
absl::SubstituteAndAppend(&str, "$0 $1 $2 $3", v[0], v[1], cv[0], cv[1]);
EXPECT_EQ("Logic be like: true false true false", str);
}
#ifdef GTEST_HAS_DEATH_TEST #ifdef GTEST_HAS_DEATH_TEST
TEST(SubstituteDeathTest, SubstituteDeath) { TEST(SubstituteDeathTest, SubstituteDeath) {