Export of internal Abseil changes.
-- f9f068aa8a260dc576398e47b8e4540902e41358 by Derek Mauro <dmauro@google.com>: Fix test string with embedded NUL. Currently parses as octal. PiperOrigin-RevId: 237088193 -- d271ffdd3f450f817f6d30e98ff39d439aaf3a98 by Abseil Team <absl-team@google.com>: Make symbolizer examine any mapping with read+exec permission regardless of 'w' bit. PiperOrigin-RevId: 237056461 -- af315f8306d36a7367a452fd0b58cafdbf20719d by Abseil Team <absl-team@google.com>: Switch comments referencing base:: CondVar and Mutex to absl::. PiperOrigin-RevId: 236917884 -- c624d5d1c0bdb917bff5e651ba40599472f84e0e by Gennadiy Rozental <rogeeff@google.com>: Internal change PiperOrigin-RevId: 236898300 -- 3cdc82429af964846d1152f49148abc61d196a4b by Samuel Benzaquen <sbenza@google.com>: Make the `long double` overload if AbslHashValue a template to avoid invalid conversions with implicit operators. This overload was never meant to capture anything other than `long double` and any current caller to it that wasn't a `long double` is potentially a bug. In particular, any type with an implicit `bool` conversion is calling this overload instead of trying to find a hash<> specialization, thus causing pretty bad hash behavior. PiperOrigin-RevId: 236877073 GitOrigin-RevId: f9f068aa8a260dc576398e47b8e4540902e41358 Change-Id: If9cc008dd814f0ca06ed881f612c06575f1f7137
This commit is contained in:
parent
9fdf5e5b80
commit
febc5ee6a9
70 changed files with 483 additions and 410 deletions
|
|
@ -18,13 +18,13 @@
|
|||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// This header file contains functions for joining a range of elements and
|
||||
// returning the result as a string. StrJoin operations are specified by passing
|
||||
// a range, a separator string to use between the elements joined, and an
|
||||
// optional Formatter responsible for converting each argument in the range to a
|
||||
// string. If omitted, a default `AlphaNumFormatter()` is called on the elements
|
||||
// to be joined, using the same formatting that `absl::StrCat()` uses. This
|
||||
// package defines a number of default formatters, and you can define your own
|
||||
// implementations.
|
||||
// returning the result as a std::string. StrJoin operations are specified by
|
||||
// passing a range, a separator string to use between the elements joined, and
|
||||
// an optional Formatter responsible for converting each argument in the range
|
||||
// to a string. If omitted, a default `AlphaNumFormatter()` is called on the
|
||||
// elements to be joined, using the same formatting that `absl::StrCat()` uses.
|
||||
// This package defines a number of default formatters, and you can define your
|
||||
// own implementations.
|
||||
//
|
||||
// Ranges are specified by passing a container with `std::begin()` and
|
||||
// `std::end()` iterators, container-specific `begin()` and `end()` iterators, a
|
||||
|
|
@ -37,8 +37,8 @@
|
|||
//
|
||||
// Example:
|
||||
//
|
||||
// std::vector<string> v = {"foo", "bar", "baz"};
|
||||
// string s = absl::StrJoin(v, "-");
|
||||
// std::vector<std::string> v = {"foo", "bar", "baz"};
|
||||
// std::string s = absl::StrJoin(v, "-");
|
||||
// EXPECT_EQ("foo-bar-baz", s);
|
||||
//
|
||||
// See comments on the `absl::StrJoin()` function for more examples.
|
||||
|
|
@ -66,16 +66,16 @@ namespace absl {
|
|||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// A Formatter is a function object that is responsible for formatting its
|
||||
// argument as a string and appending it to a given output string. Formatters
|
||||
// may be implemented as function objects, lambdas, or normal functions. You may
|
||||
// provide your own Formatter to enable `absl::StrJoin()` to work with arbitrary
|
||||
// types.
|
||||
// argument as a string and appending it to a given output std::string.
|
||||
// Formatters may be implemented as function objects, lambdas, or normal
|
||||
// functions. You may provide your own Formatter to enable `absl::StrJoin()` to
|
||||
// work with arbitrary types.
|
||||
//
|
||||
// The following is an example of a custom Formatter that simply uses
|
||||
// `std::to_string()` to format an integer as a string.
|
||||
// `std::to_string()` to format an integer as a std::string.
|
||||
//
|
||||
// struct MyFormatter {
|
||||
// void operator()(string* out, int i) const {
|
||||
// void operator()(std::string* out, int i) const {
|
||||
// out->append(std::to_string(i));
|
||||
// }
|
||||
// };
|
||||
|
|
@ -84,7 +84,7 @@ namespace absl {
|
|||
// argument to `absl::StrJoin()`:
|
||||
//
|
||||
// std::vector<int> v = {1, 2, 3, 4};
|
||||
// string s = absl::StrJoin(v, "-", MyFormatter());
|
||||
// std::string s = absl::StrJoin(v, "-", MyFormatter());
|
||||
// EXPECT_EQ("1-2-3-4", s);
|
||||
//
|
||||
// The following standard formatters are provided within this file:
|
||||
|
|
@ -156,7 +156,7 @@ DereferenceFormatter() {
|
|||
// StrJoin()
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// Joins a range of elements and returns the result as a string.
|
||||
// Joins a range of elements and returns the result as a std::string.
|
||||
// `absl::StrJoin()` takes a range, a separator string to use between the
|
||||
// elements joined, and an optional Formatter responsible for converting each
|
||||
// argument in the range to a string.
|
||||
|
|
@ -167,22 +167,22 @@ DereferenceFormatter() {
|
|||
// Example 1:
|
||||
// // Joins a collection of strings. This pattern also works with a collection
|
||||
// // of `absl::string_view` or even `const char*`.
|
||||
// std::vector<string> v = {"foo", "bar", "baz"};
|
||||
// string s = absl::StrJoin(v, "-");
|
||||
// std::vector<std::string> v = {"foo", "bar", "baz"};
|
||||
// std::string s = absl::StrJoin(v, "-");
|
||||
// EXPECT_EQ("foo-bar-baz", s);
|
||||
//
|
||||
// Example 2:
|
||||
// // Joins the values in the given `std::initializer_list<>` specified using
|
||||
// // brace initialization. This pattern also works with an initializer_list
|
||||
// // of ints or `absl::string_view` -- any `AlphaNum`-compatible type.
|
||||
// string s = absl::StrJoin({"foo", "bar", "baz"}, "-");
|
||||
// std::string s = absl::StrJoin({"foo", "bar", "baz"}, "-");
|
||||
// EXPECT_EQ("foo-bar-baz", s);
|
||||
//
|
||||
// Example 3:
|
||||
// // Joins a collection of ints. This pattern also works with floats,
|
||||
// // doubles, int64s -- any `StrCat()`-compatible type.
|
||||
// std::vector<int> v = {1, 2, 3, -4};
|
||||
// string s = absl::StrJoin(v, "-");
|
||||
// std::string s = absl::StrJoin(v, "-");
|
||||
// EXPECT_EQ("1-2-3--4", s);
|
||||
//
|
||||
// Example 4:
|
||||
|
|
@ -193,7 +193,7 @@ DereferenceFormatter() {
|
|||
// // `std::vector<int*>`.
|
||||
// int x = 1, y = 2, z = 3;
|
||||
// std::vector<int*> v = {&x, &y, &z};
|
||||
// string s = absl::StrJoin(v, "-");
|
||||
// std::string s = absl::StrJoin(v, "-");
|
||||
// EXPECT_EQ("1-2-3", s);
|
||||
//
|
||||
// Example 5:
|
||||
|
|
@ -202,53 +202,53 @@ DereferenceFormatter() {
|
|||
// v.emplace_back(new int(1));
|
||||
// v.emplace_back(new int(2));
|
||||
// v.emplace_back(new int(3));
|
||||
// string s = absl::StrJoin(v, "-");
|
||||
// std::string s = absl::StrJoin(v, "-");
|
||||
// EXPECT_EQ("1-2-3", s);
|
||||
//
|
||||
// Example 6:
|
||||
// // Joins a `std::map`, with each key-value pair separated by an equals
|
||||
// // sign. This pattern would also work with, say, a
|
||||
// // `std::vector<std::pair<>>`.
|
||||
// std::map<string, int> m = {
|
||||
// std::map<std::string, int> m = {
|
||||
// std::make_pair("a", 1),
|
||||
// std::make_pair("b", 2),
|
||||
// std::make_pair("c", 3)};
|
||||
// string s = absl::StrJoin(m, ",", absl::PairFormatter("="));
|
||||
// std::string s = absl::StrJoin(m, ",", absl::PairFormatter("="));
|
||||
// EXPECT_EQ("a=1,b=2,c=3", s);
|
||||
//
|
||||
// Example 7:
|
||||
// // These examples show how `absl::StrJoin()` handles a few common edge
|
||||
// // cases:
|
||||
// std::vector<string> v_empty;
|
||||
// std::vector<std::string> v_empty;
|
||||
// EXPECT_EQ("", absl::StrJoin(v_empty, "-"));
|
||||
//
|
||||
// std::vector<string> v_one_item = {"foo"};
|
||||
// std::vector<std::string> v_one_item = {"foo"};
|
||||
// EXPECT_EQ("foo", absl::StrJoin(v_one_item, "-"));
|
||||
//
|
||||
// std::vector<string> v_empty_string = {""};
|
||||
// std::vector<std::string> v_empty_string = {""};
|
||||
// EXPECT_EQ("", absl::StrJoin(v_empty_string, "-"));
|
||||
//
|
||||
// std::vector<string> v_one_item_empty_string = {"a", ""};
|
||||
// std::vector<std::string> v_one_item_empty_string = {"a", ""};
|
||||
// EXPECT_EQ("a-", absl::StrJoin(v_one_item_empty_string, "-"));
|
||||
//
|
||||
// std::vector<string> v_two_empty_string = {"", ""};
|
||||
// std::vector<std::string> v_two_empty_string = {"", ""};
|
||||
// EXPECT_EQ("-", absl::StrJoin(v_two_empty_string, "-"));
|
||||
//
|
||||
// Example 8:
|
||||
// // Joins a `std::tuple<T...>` of heterogeneous types, converting each to
|
||||
// // a string using the `absl::AlphaNum` class.
|
||||
// string s = absl::StrJoin(std::make_tuple(123, "abc", 0.456), "-");
|
||||
// // a std::string using the `absl::AlphaNum` class.
|
||||
// std::string s = absl::StrJoin(std::make_tuple(123, "abc", 0.456), "-");
|
||||
// EXPECT_EQ("123-abc-0.456", s);
|
||||
|
||||
template <typename Iterator, typename Formatter>
|
||||
std::string StrJoin(Iterator start, Iterator end, absl::string_view sep,
|
||||
Formatter&& fmt) {
|
||||
Formatter&& fmt) {
|
||||
return strings_internal::JoinAlgorithm(start, end, sep, fmt);
|
||||
}
|
||||
|
||||
template <typename Range, typename Formatter>
|
||||
std::string StrJoin(const Range& range, absl::string_view separator,
|
||||
Formatter&& fmt) {
|
||||
Formatter&& fmt) {
|
||||
return strings_internal::JoinRange(range, separator, fmt);
|
||||
}
|
||||
|
||||
|
|
@ -260,7 +260,7 @@ std::string StrJoin(std::initializer_list<T> il, absl::string_view separator,
|
|||
|
||||
template <typename... T, typename Formatter>
|
||||
std::string StrJoin(const std::tuple<T...>& value, absl::string_view separator,
|
||||
Formatter&& fmt) {
|
||||
Formatter&& fmt) {
|
||||
return strings_internal::JoinAlgorithm(value, separator, fmt);
|
||||
}
|
||||
|
||||
|
|
@ -280,7 +280,8 @@ std::string StrJoin(std::initializer_list<T> il, absl::string_view separator) {
|
|||
}
|
||||
|
||||
template <typename... T>
|
||||
std::string StrJoin(const std::tuple<T...>& value, absl::string_view separator) {
|
||||
std::string StrJoin(const std::tuple<T...>& value,
|
||||
absl::string_view separator) {
|
||||
return strings_internal::JoinAlgorithm(value, separator, AlphaNumFormatter());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue