Changes imported from Abseil "staging" branch:

- 06c8c67f5a564d00696e023060f05a5c34e7e164 IWYU | absl/base by Juemin Yang <jueminyang@google.com>
  - 2b1a054a09bda55843b449843b2a125741e936e7 Internal refactoring by Greg Miller <jgm@google.com>
  - f43f7f1f91bee26b5ddcd0c5bbbc47cb977aef77 Make std::hash<absl::optional<T>> to be standard compliant: by Xiaoyi Zhang <zhangxy@google.com>
  - 539bad2ebc22e610e1f292285a30a87945bc663e Update utility.h to Abseil standards by Tom Manshreck <shreck@google.com>
  - d05ec10a5f16a5d6640e0db91ecc7ab3ea971fd4 Add a test for absl::Barrier. by Derek Mauro <dmauro@google.com>
  - d707e27acb3c06f0d74c5f7ad7861e3841a5471f Run leak-checking tool over all outbound code. by Daniel Katz <katzdm@google.com>
  - 55f07f482a50422b8f99f7176374a19d0d473c5f Add alignas(16) to uint128. by Alex Strelnikov <strel@google.com>
  - 94999b7edde82308f736fb939501537ee9edbca6 Update attributes.h to Abseil standards by Tom Manshreck <shreck@google.com>
  - 321bed0061c41b53d0206ad4865528c00dd6d825 Test git merge + piper cl process by Juemin Yang <jueminyang@google.com>
  - 69920e7351a1053a7f4940bbde1768e839ce84bc Adds support for "/etc/localtime" as an embedded time zon... by Greg Miller <jgm@google.com>
  - 6839c06bf232903d3a9cbffa6eb2c960db78e67b Add copyright notices to inlined_vector code. by Greg Falcon <gfalcon@google.com>
  - 4e2714f6266263515cdfd31675c30c6ed6f98e1a Adding Apache 2.0 License by Gennadiy Civil <misterg@google.com>
  - 7402e7594016a4cd0a8b823fe6bc1bad1874bb85 IWYU | absl/utility by Juemin Yang <jueminyang@google.com>
  - 271a3812337eed97c412042738482688a80e19bd IWYU | absl/memory by Juemin Yang <jueminyang@google.com>
  - 32bda13a8098c2b06e25a5cf7bb782d6b79eb006 IWYU | absl/numeric by Juemin Yang <jueminyang@google.com>
  - 62d375cedc133108904bc06e340e303091a565df Remove "no_test"-annotations on span_test_noexceptions. by Daniel Katz <katzdm@google.com>
  - ebcbae9a55a93a7f1bb6862edc2715a6d9877206 Move CI-testing support files out of public-facing reposi... by Daniel Katz <katzdm@google.com>
  - d3f05eff4daa6030bfacb31cca0f9213fb702247 Fixes ToInt64Minutes() and ToInt64Hours() to properly sat... by Greg Miller <jgm@google.com>
  - b8dfae3facb6bb002622f083a10d14448f19e6e0 Fix typo. by Abseil Team <absl-team@google.com>
  - 150f03baa0afa231c2fc01597ea2321da586caba Update README.md by Yilei Yang <yileiyang@google.com>
  - 05276aa837dd081686518fd27bda4bd206ac4443 Adding Apache 2.0 License by Gennadiy Civil <misterg@google.com>
  - 37bf8e223e79ad06a195e28db9499e0c3d140f73 IWYU | absl/container by Juemin Yang <jueminyang@google.com>
  - 49164928f220978a32f88d16a55549bdf871daef IWYU | absl/algorithm by Juemin Yang <jueminyang@google.com>
  - a6804734e129039f9580a4fcd0f66425d0d0ac30 Move throw delegate wrappers to an internal namespace. by Greg Falcon <gfalcon@google.com>
  - ac83e73f67f593e2aff957b2be0b28e59c552a71 Fix error in comment stripping directives. by Greg Falcon <gfalcon@google.com>
  - e018a24185a984e787fb81a75fc35b74ad3a4d3d Update copyright headers all BUILD files by Gennadiy Civil <misterg@google.com>
  - a3be0990bfd76b0dec76bd85cecfa4dcec68b3ea Fix closing namespace comment typo. by Abseil Team <absl-team@google.com>
  - be3e3c4327e4f83949e0f29fd7a190d7eaa8b50b Update TODO by Abseil Team <absl-team@google.com>
  - f56a5d6f72685d92bb9c2905841b950d8177210c Add test-coverage for leak-sanitizer. by Daniel Katz <katzdm@google.com>
  - 7694bf161c7e00fdd08bfadc2aaf8e0fb09335f8 span.h: further touch up wording around the std::initiali... by Abseil Team <absl-team@google.com>
  - 3a12e081c0f8b359973e020d1e91f65356548ebc Update time.h to Abseil standards by Tom Manshreck <shreck@google.com>
  - 48d28f6468129420f4b20d451dca8e08012a7a77 Remove references to google from comments in Abseil. by Greg Falcon <gfalcon@google.com>
  - 773e34402d15fcad6370d5ed2430482d17db910d Rename the ExpectTime macro to match Abseil naming conven... by Greg Falcon <gfalcon@google.com>
  - 774d2ff1fe26c7313b301ff203e83e1aaac86627 Internal change. by Daniel Katz <katzdm@google.com>
  - 2e8a5830e95c8a1b839721bb2f1d4f5c85b9fb60 Fix typo in comment (missing '*' on a pointer). by Abseil Team <absl-team@google.com>
  - 458106feb707cf9609dd243713bde44aa9679e2a Correct capitalization: github -> GitHub by Yilei Yang <yileiyang@google.com>
  - af440725f02c2a83ca5cbaf176e1142f9e9d9b2f Update copyright headers by Gennadiy Civil <misterg@google.com>
  - 05b1118cce4ab87d23c33d48e64a96bcfec08761 Update copyright headers by Gennadiy Civil <misterg@google.com>
  - d5c6669a62d047156bb77055c5da03ee1b3c61b9 Update Abseil README to include descriptions of the inclu... by Tom Manshreck <shreck@google.com>
  - 3cd7e4663dddc840087469a6495f6cf433bfad8d Update copyright headers in //base by Tom Manshreck <shreck@google.com>
  - 7a876da657cd6698c5da2008a582d52eedc85dd1 Update strings overview with robust string library docume... by Tom Manshreck <shreck@google.com>
  - d9e3d0768d6f1c77d30992bdbef7b47ec92994bb Update copyright headers all BUILD files by Abseil Team <absl-team@google.com>
  - 6fe942728bceb0625f7c79b2840c4a6154d076b3 Make InlinedVector, FixedArray, and Span's at() throw on ... by Jon Cohen <cohenjon@google.com>
  - 5b52d5ec6cb9fbb07fc2e2fa020bd3eeb48c4953 Update clock.h to Abseil standards by Tom Manshreck <shreck@google.com>
  - c03c1ca3aee8bb7e40aa0315f6c432d31a72c30c Update //algorithm copyright headers by Tom Manshreck <shreck@google.com>
  - d46f40ddc596aaacb0459351d0e4aa6871289fa2 Temporarily prevent running mutex_test on crosstool17, wh... by Jon Cohen <cohenjon@google.com>
  - 61f11476189df68edfb9908308d677a91f03ff67 Update copyright headers in //container by Tom Manshreck <shreck@google.com>
  - 91832c00948954edf0b3dda12219c9a0202421ac Update copyright headers for //synchronization by Tom Manshreck <shreck@google.com>
  - 4e09100264b4585af6b4508ff35b9c627ac1f1ce Update copyright headers all BUILD files by Gennadiy Civil <misterg@google.com>
  - 13a0e8aebedec0f95b33750cbcd6b5548619b2a5 Update copyright headers in //memory by Tom Manshreck <shreck@google.com>
  - 63e1b9d4fdbcdf097e5276050ad1f76f0053e553 Update copyright headers for //strings (+ one from //nume... by Tom Manshreck <shreck@google.com>
  - 0108e7cfc50777a94c56d00e9c305161364df341 Convert ASSERT and EXPECT to ABSL_RAW_CHECK in helper fun... by Derek Mauro <dmauro@google.com>
  - 0122306fe47a3093248254a1b475c3a1d82abec5 Internal change by Abseil Team <absl-team@google.com>
  - 89c0c2698c98a12cd63172eeb02063b2f67e7c81 #absl Fix comment. by Abseil Team <absl-team@google.com>
  - 6621cc1ff54800e0aadb5e3071dbaa84b2077ceb Publishing contributing guidelines. by Gennadiy Civil <misterg@google.com>
  - e48c5be3c75e794b3e3827d40915b01fe1a1afc5 Avoid PRIdPTR.  Cast to long long and use %lld insted. by Abseil Team <absl-team@google.com>
  - 2640ea4a260d89b94b07a3142660327e47db33fd No algorithmic changes. by Abseil Team <absl-team@google.com>
  - 1bc6c1bad17754f5d84963bf1d0db279402a0a1d Internal change. by Derek Mauro <dmauro@google.com>
  - 6845d24733e8c95bebde825ba78a2abfd9e35bdb span.h: fix up incorrect wording around lvalues. by Abseil Team <absl-team@google.com>
  - d8f5caee721e252e5f9b1080fb996363f498ac28 Add more exaustive Mutex testing. by Derek Mauro <dmauro@google.com>
  - e8b4cb053eb98858eef10cc53280b6ed5d6815a7 Change Span::subspan to not call into a deprecated constr... by Jon Cohen <cohenjon@google.com>
  - 49c36a82b3114926390557670aaaf0ea25b5760c s/std::size_t/size_t/g by Jon Cohen <cohenjon@google.com>
  - e17487c3c4d4a99f2fd8bc3e42176fc3171614d1 Account for the case of timeval::tv_sec being smaller than by Abseil Team <absl-team@google.com>
  - ecbb89d5fb98483e777c03d97ac02d7b7b54985e Alias absl::string_view to std::string_view when C++17 st... by Xiaoyi Zhang <zhangxy@google.com>
  - 6820e5a51459cdbb6a423cbae25a0cc839c85d44 Internal cleanup. by Xiaoyi Zhang <zhangxy@google.com>
  - 6976469b76a6faaf4111a24ddb37f40211ffadae More Span constexpr by Jon Cohen <cohenjon@google.com>
  - 8521c8956eee1125b7759eb272ec4a5a86fcefc5 #absl Fix comment. by Abseil Team <absl-team@google.com>
  - 20eae7a67fde5dd809aa47e5f7de8a493701645e Embed enough zoneinfo data to make time:time_test (under ... by Abseil Team <absl-team@google.com>
  - 841f5d98ceef4a423839ea73ee06c2f47a9b9680 Clean up macros in attributes.h | ATTRIBUTE_INITIAL_EXEC by Juemin Yang <jueminyang@google.com>
  - 83d8b36656e47919b5d0bac82eece897e195697e Update any.h comments to Abseil standards by Tom Manshreck <shreck@google.com>
  - bb3fae11d3459eeae2f63bfd22e65d3193187cc8 Update type_traits.h comments to Abseil standards by Tom Manshreck <shreck@google.com>
  - 992e1b07c0dec64271f8c44f22fd8df3734d0c47 Renamespace CycleClock code. by Greg Falcon <gfalcon@google.com>
  - 08d6fb0594098493ffbc0e737405182638122e7e Eliminate more existing lint warnings by Gennadiy Rozental <rogeeff@google.com>
  - 1cc6fdc71eb777497239f8c3e9168e6c9d40ea53 Update optional.h to Abseil standards by Tom Manshreck <shreck@google.com>
  - baa91747aa55009a9eb31b6072e33db06cfce2d2 Enforce internal namespace symbol reference policy by Gennadiy Rozental <rogeeff@google.com>
  - 939251e39342ce559e5d23fe43799671581f7cf5 Add CycleClock scaling shift to mitigate a possible overf... by Derek Mauro <dmauro@google.com>
  - c6dfdeecea0c7470938bed47c99ea2b2a95889d8 Add constexpr tests for absl::make_optional(). by Xiaoyi Zhang <zhangxy@google.com>
  - 509e949b992db33041d840746fbd05cc01cb206e Alias absl::optional to std::optional when C++17 std::opt... by Xiaoyi Zhang <zhangxy@google.com>
  - a1ae6d96a8826ba75281cac8632a766b5856acaf Remove no_test_* tags from span_test to increase test cov... by Xiaoyi Zhang <zhangxy@google.com>
  - 3c2a43cc09791723c8a324836629644ac44cb9c8 Remove accidental bits of Google-internal code and short ... by Greg Falcon <gfalcon@google.com>
  - 4874d49d496ac0b6ec36f4280a14b2159e7af930 Replaces the macro-generated Duration factory functions e... by Greg Miller <jgm@google.com>
  - 90e62695e03cb4a57e137ca0c3e116b1d802db57 Fix namespacing for a couple files in base/internal, and ... by Greg Falcon <gfalcon@google.com>
  - b0e6e00e34f967924849aaf8c123bba068f093e3 Publishing contributing guidelines. by Gennadiy Civil <misterg@google.com>
  - d74eafbccc3dffa6c25f9b6a2219425a24b5a959 Internal change by Abseil Team <absl-team@google.com>
  - 27477badbbf720265f5b9509b6c0e01913dc0a9f Update escaping.h comments to Abseil standards by Tom Manshreck <shreck@google.com>
  - 67002f55738319c2875197c3b6282de215ec250d adds absl namespace to debugging/stacktrace.h by Behzad Nouri <bnouri@google.com>
  - e608018f7faa384d5b202ac0a4c7a0d5166f4d9c Update string_view.h comments to Abseil standards by Tom Manshreck <shreck@google.com>
  - e884f04d4c648e01ed7dcde2fda80c24e8452047 Exclude strings/ files we are not releasing from OSS univ... by Gennadiy Rozental <rogeeff@google.com>
  - 3f4c4032ed520f2dd10a81d58ef4f399c001c5cc Strip out eventmanager reference from release. by Gennadiy Rozental <rogeeff@google.com>
  - fb0f1c204793c3792bad101dbaa734e7c2a35887 Fix copybara strip comments by Gennadiy Rozental <rogeeff@google.com>
  - 3eaaac942f77c3d41d63d414630403bfd0f6b70c Strip out style guide waivers. by Gennadiy Rozental <rogeeff@google.com>
  - 020e045058173178b51266b99a2a5dc9ed921960 substitute_test portability | MUST_USE_RESULT cast-to-voi... by Juemin Yang <jueminyang@google.com>
  - 86c093bf81d80ff537ed5e8b89225ce75a636220 Internal change. by Derek Mauro <dmauro@google.com>
  - 330375eb952fe78276e75631a28e750d5bfdb198 Prefer absl::FixedTimeZone() over loading "Etc/GMT[-+]<N>". by Abseil Team <absl-team@google.com>
  - 2e07ebee46a8201adc0dfd2c4ddb3df76e524357 Internal change. by Derek Mauro <dmauro@google.com>
  - 1f0c8b78c8ebd66f14cdf39fcba9f4c9986dcdca ::absl -> absl by Gennadiy Rozental <rogeeff@google.com>
  - ad163566d12ea08f1da2c23931eeacfffc564139 Avoid old style loops where possible. by Gennadiy Rozental <rogeeff@google.com>
  - bce2108818fe57b5617ce0090ddd4f753808f0a1 Update comments in str_cat.h in line with recent changes. by Abseil Team <absl-team@google.com>
  - cfd593a80f4897256f2ce1ea0be55dc14e3fcad4 Copybara-out gtl aliases. by Gennadiy Rozental <rogeeff@google.com>
  - 584f1524d717993c1a16093caccd9ed2b1e5409e Fix a warning for Windows/Kokoro time_test.cc. by Daniel Katz <katzdm@google.com>
  (And 562 more changes)

GitOrigin-RevId: 06c8c67f5a564d00696e023060f05a5c34e7e164
Change-Id: I89907a6188fe7de05da400bf49ddfeba242aff8e
This commit is contained in:
Abseil Team 2017-09-19 17:15:26 -07:00 committed by misterg
parent c2e7548296
commit 53c239d1fc
35 changed files with 440 additions and 152 deletions

View file

@ -7,7 +7,6 @@ http_archive(
) )
# CCTZ (Time-zone framework). # CCTZ (Time-zone framework).
# TODO(b/63158562): Make test and benchmark targets from here build.
http_archive( http_archive(
name = "com_googlesource_code_cctz", name = "com_googlesource_code_cctz",
urls = ["https://github.com/google/cctz/archive/master.zip"], urls = ["https://github.com/google/cctz/archive/master.zip"],

View file

@ -121,6 +121,7 @@ cc_library(
":config", ":config",
":core_headers", ":core_headers",
":dynamic_annotations", ":dynamic_annotations",
":spinlock_wait",
], ],
) )
@ -192,6 +193,7 @@ cc_library(
deps = [ deps = [
":base", ":base",
":config", ":config",
":core_headers",
], ],
) )
@ -236,6 +238,8 @@ cc_library(
copts = ABSL_TEST_COPTS, copts = ABSL_TEST_COPTS,
deps = [ deps = [
":base", ":base",
":core_headers",
":spinlock_wait",
"//absl/synchronization", "//absl/synchronization",
"@com_google_googletest//:gtest", "@com_google_googletest//:gtest",
], ],
@ -249,6 +253,8 @@ cc_test(
copts = ABSL_TEST_COPTS, copts = ABSL_TEST_COPTS,
deps = [ deps = [
":base", ":base",
":core_headers",
":spinlock_wait",
"//absl/synchronization", "//absl/synchronization",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
], ],
@ -342,6 +348,7 @@ cc_test(
}), }),
deps = [ deps = [
":base", ":base",
":core_headers",
"//absl/synchronization", "//absl/synchronization",
] + select(GUNIT_MAIN_DEPS_SELECTOR), ] + select(GUNIT_MAIN_DEPS_SELECTOR),
) )

View file

@ -12,39 +12,61 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
// //
// Various macros for C++ attributes // This header file defines macros for declaring attributes for functions,
// types, and variables.
//
// These macros are used within Abseil and allow the compiler to optimize, where
// applicable, certain function calls.
//
// This file is used for both C and C++! // This file is used for both C and C++!
// //
// Most macros here are exposing GCC or Clang features, and are stubbed out for // Most macros here are exposing GCC or Clang features, and are stubbed out for
// other compilers. // other compilers.
//
// GCC attributes documentation: // GCC attributes documentation:
// https://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Function-Attributes.html // https://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Function-Attributes.html
// https://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Variable-Attributes.html // https://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Variable-Attributes.html
// https://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Type-Attributes.html // https://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Type-Attributes.html
// //
// Most attributes in this file are already supported by GCC 4.7. // Most attributes in this file are already supported by GCC 4.7. However, some
// However, some of them are not supported in older version of Clang. // of them are not supported in older version of Clang. Thus, we check
// Thus, we check __has_attribute() first. If the check fails, we check if we // `__has_attribute()` first. If the check fails, we check if we are on GCC and
// are on GCC and assume the attribute exists on GCC (which is verified on GCC // assume the attribute exists on GCC (which is verified on GCC 4.7).
// 4.7).
// //
// For sanitizer-related attributes, define the following macros // -----------------------------------------------------------------------------
// using -D along with the given value for -fsanitize: // Sanitizer Attributes
// - ADDRESS_SANITIZER with -fsanitize=address (GCC 4.8+, Clang) // -----------------------------------------------------------------------------
// - MEMORY_SANITIZER with -fsanitize=memory (Clang) //
// - THREAD_SANITIZER with -fsanitize=thread (GCC 4.8+, Clang) // Sanitizer-related attributes are not "defined" in this file (and indeed
// - UNDEFINED_BEHAVIOR_SANITIZER with -fsanitize=undefined (GCC 4.9+, Clang) // are not defined as such in any file). To utilize the following
// - CONTROL_FLOW_INTEGRITY with -fsanitize=cfi (Clang) // sanitizer-related attributes within your builds, define the following macros
// Since these are only supported by GCC and Clang now, we only check for // within your build using a `-D` flag, along with the given value for
// __GNUC__ (GCC or Clang) and the above macros. // `-fsanitize`:
//
// * `ADDRESS_SANITIZER` + `-fsanitize=address` (Clang, GCC 4.8)
// * `MEMORY_SANITIZER` + `-fsanitize=memory` (Clang-only)
// * `THREAD_SANITIZER + `-fsanitize=thread` (Clang, GCC 4.8+)
// * `UNDEFINED_BEHAVIOR_SANITIZER` + `-fsanitize=undefined` (Clang, GCC 4.9+)
// * `CONTROL_FLOW_INTEGRITY` + -fsanitize=cfi (Clang-only)
//
// Example:
//
// // Enable branches in the Abseil code that are tagged for ASan:
// $ bazel -D ADDRESS_SANITIZER -fsanitize=address *target*
//
// Since these macro names are only supported by GCC and Clang, we only check
// for `__GNUC__` (GCC or Clang) and the above macros.
#ifndef ABSL_BASE_ATTRIBUTES_H_ #ifndef ABSL_BASE_ATTRIBUTES_H_
#define ABSL_BASE_ATTRIBUTES_H_ #define ABSL_BASE_ATTRIBUTES_H_
// ABSL_HAVE_ATTRIBUTE is a function-like feature checking macro. // ABSL_HAVE_ATTRIBUTE
// It's a wrapper around __has_attribute, which is defined by GCC 5+ and Clang. //
// It evaluates to a nonzero constant integer if the attribute is supported // A function-like feature checking macro that is a wrapper around
// or 0 if not. // `__has_attribute`, which is defined by GCC 5+ and Clang and evaluates to a
// It evaluates to zero if __has_attribute is not defined by the compiler. // nonzero constant integer if the attribute is supported or 0 if not.
//
// It evaluates to zero if `__has_attribute` is not defined by the compiler.
//
// GCC: https://gcc.gnu.org/gcc-5/changes.html // GCC: https://gcc.gnu.org/gcc-5/changes.html
// Clang: https://clang.llvm.org/docs/LanguageExtensions.html // Clang: https://clang.llvm.org/docs/LanguageExtensions.html
#ifdef __has_attribute #ifdef __has_attribute
@ -53,11 +75,12 @@
#define ABSL_HAVE_ATTRIBUTE(x) 0 #define ABSL_HAVE_ATTRIBUTE(x) 0
#endif #endif
// ABSL_HAVE_CPP_ATTRIBUTE is a function-like feature checking macro that // ABSL_HAVE_CPP_ATTRIBUTE
// accepts C++11 style attributes. It's a wrapper around __has_cpp_attribute, //
// defined by ISO C++ SD-6 // A function-like feature checking macro that accepts C++11 style attributes.
// It's a wrapper around `__has_cpp_attribute`, defined by ISO C++ SD-6
// (http://en.cppreference.com/w/cpp/experimental/feature_test). If we don't // (http://en.cppreference.com/w/cpp/experimental/feature_test). If we don't
// find __has_cpp_attribute, will evaluate to 0. // find `__has_cpp_attribute`, will evaluate to 0.
#if defined(__cplusplus) && defined(__has_cpp_attribute) #if defined(__cplusplus) && defined(__has_cpp_attribute)
// NOTE: requiring __cplusplus above should not be necessary, but // NOTE: requiring __cplusplus above should not be necessary, but
// works around https://bugs.llvm.org/show_bug.cgi?id=23435. // works around https://bugs.llvm.org/show_bug.cgi?id=23435.
@ -69,15 +92,18 @@
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Function Attributes // Function Attributes
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
//
// GCC: https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html // GCC: https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
// Clang: https://clang.llvm.org/docs/AttributeReference.html // Clang: https://clang.llvm.org/docs/AttributeReference.html
// ABSL_PRINTF_ATTRIBUTE, ABSL_SCANF_ATTRIBUTE // ABSL_PRINTF_ATTRIBUTE
// Tell the compiler to do printf format std::string checking if the // ABSL_SCANF_ATTRIBUTE
//
// Tells the compiler to perform `printf` format std::string checking if the
// compiler supports it; see the 'format' attribute in // compiler supports it; see the 'format' attribute in
// <http://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Function-Attributes.html>. // <http://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Function-Attributes.html>.
// //
// N.B.: As the GCC manual states, "[s]ince non-static C++ methods // Note: As the GCC manual states, "[s]ince non-static C++ methods
// have an implicit 'this' argument, the arguments of such methods // have an implicit 'this' argument, the arguments of such methods
// should be counted from two, not one." // should be counted from two, not one."
#if ABSL_HAVE_ATTRIBUTE(format) || (defined(__GNUC__) && !defined(__clang__)) #if ABSL_HAVE_ATTRIBUTE(format) || (defined(__GNUC__) && !defined(__clang__))
@ -90,9 +116,10 @@
#define ABSL_SCANF_ATTRIBUTE(string_index, first_to_check) #define ABSL_SCANF_ATTRIBUTE(string_index, first_to_check)
#endif #endif
// ABSL_ATTRIBUTE_ALWAYS_INLINE, ABSL_ATTRIBUTE_NOINLINE // ABSL_ATTRIBUTE_ALWAYS_INLINE
// For functions we want to force inline or not inline. // ABSL_ATTRIBUTE_NOINLINE
// Introduced in gcc 3.1. //
// Forces functions to either inline or not inline. Introduced in gcc 3.1.
#if ABSL_HAVE_ATTRIBUTE(always_inline) || \ #if ABSL_HAVE_ATTRIBUTE(always_inline) || \
(defined(__GNUC__) && !defined(__clang__)) (defined(__GNUC__) && !defined(__clang__))
#define ABSL_ATTRIBUTE_ALWAYS_INLINE __attribute__((always_inline)) #define ABSL_ATTRIBUTE_ALWAYS_INLINE __attribute__((always_inline))
@ -109,7 +136,8 @@
#endif #endif
// ABSL_ATTRIBUTE_NO_TAIL_CALL // ABSL_ATTRIBUTE_NO_TAIL_CALL
// Prevent the compiler from optimizing away stack frames for functions which //
// Prevents the compiler from optimizing away stack frames for functions which
// end in a call to another function. // end in a call to another function.
#if ABSL_HAVE_ATTRIBUTE(disable_tail_calls) #if ABSL_HAVE_ATTRIBUTE(disable_tail_calls)
#define ABSL_HAVE_ATTRIBUTE_NO_TAIL_CALL 1 #define ABSL_HAVE_ATTRIBUTE_NO_TAIL_CALL 1
@ -122,8 +150,10 @@
#define ABSL_ATTRIBUTE_NO_TAIL_CALL #define ABSL_ATTRIBUTE_NO_TAIL_CALL
#define ABSL_HAVE_ATTRIBUTE_NO_TAIL_CALL 0 #define ABSL_HAVE_ATTRIBUTE_NO_TAIL_CALL 0
#endif #endif
// ABSL_ATTRIBUTE_WEAK // ABSL_ATTRIBUTE_WEAK
// For weak functions //
// Tags a function as weak for the purposes of compilation and linking.
#if ABSL_HAVE_ATTRIBUTE(weak) || (defined(__GNUC__) && !defined(__clang__)) #if ABSL_HAVE_ATTRIBUTE(weak) || (defined(__GNUC__) && !defined(__clang__))
#undef ABSL_ATTRIBUTE_WEAK #undef ABSL_ATTRIBUTE_WEAK
#define ABSL_ATTRIBUTE_WEAK __attribute__((weak)) #define ABSL_ATTRIBUTE_WEAK __attribute__((weak))
@ -132,9 +162,11 @@
#define ABSL_ATTRIBUTE_WEAK #define ABSL_ATTRIBUTE_WEAK
#define ABSL_HAVE_ATTRIBUTE_WEAK 0 #define ABSL_HAVE_ATTRIBUTE_WEAK 0
#endif #endif
// ABSL_ATTRIBUTE_NONNULL // ABSL_ATTRIBUTE_NONNULL
// Tell the compiler either that a particular function parameter //
// should be a non-null pointer, or that all pointer arguments should // Tells the compiler either (a) that a particular function parameter
// should be a non-null pointer, or (b) that all pointer arguments should
// be non-null. // be non-null.
// //
// Note: As the GCC manual states, "[s]ince non-static C++ methods // Note: As the GCC manual states, "[s]ince non-static C++ methods
@ -142,10 +174,13 @@
// should be counted from two, not one." // should be counted from two, not one."
// //
// Args are indexed starting at 1. // Args are indexed starting at 1.
// For non-static class member functions, the implicit "this" argument //
// is arg 1, and the first explicit argument is arg 2. // For non-static class member functions, the implicit `this` argument
// For static class member functions, there is no implicit "this", and // is arg 1, and the first explicit argument is arg 2. For static class member
// the first explicit argument is arg 1. // functions, there is no implicit `this`, and the first explicit argument is
// arg 1.
//
// Example:
// //
// /* arg_a cannot be null, but arg_b can */ // /* arg_a cannot be null, but arg_b can */
// void Function(void* arg_a, void* arg_b) ABSL_ATTRIBUTE_NONNULL(1); // void Function(void* arg_a, void* arg_b) ABSL_ATTRIBUTE_NONNULL(1);
@ -171,8 +206,10 @@
#else #else
#define ABSL_ATTRIBUTE_NONNULL(...) #define ABSL_ATTRIBUTE_NONNULL(...)
#endif #endif
// ABSL_ATTRIBUTE_NORETURN // ABSL_ATTRIBUTE_NORETURN
// Tell the compiler that a given function never returns //
// Tells the compiler that a given function never returns.
#if ABSL_HAVE_ATTRIBUTE(noreturn) || (defined(__GNUC__) && !defined(__clang__)) #if ABSL_HAVE_ATTRIBUTE(noreturn) || (defined(__GNUC__) && !defined(__clang__))
#define ABSL_ATTRIBUTE_NORETURN __attribute__((noreturn)) #define ABSL_ATTRIBUTE_NORETURN __attribute__((noreturn))
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
@ -180,8 +217,10 @@
#else #else
#define ABSL_ATTRIBUTE_NORETURN #define ABSL_ATTRIBUTE_NORETURN
#endif #endif
// ABSL_ATTRIBUTE_NO_SANITIZE_ADDRESS // ABSL_ATTRIBUTE_NO_SANITIZE_ADDRESS
// Tell AddressSanitizer (or other memory testing tools) to ignore a given //
// Tells the AddressSanitizer (or other memory testing tools) to ignore a given
// function. Useful for cases when a function reads random locations on stack, // function. Useful for cases when a function reads random locations on stack,
// calls _exit from a cloned subprocess, deliberately accesses buffer // calls _exit from a cloned subprocess, deliberately accesses buffer
// out of bounds or does other scary things with memory. // out of bounds or does other scary things with memory.
@ -194,11 +233,12 @@
#endif #endif
// ABSL_ATTRIBUTE_NO_SANITIZE_MEMORY // ABSL_ATTRIBUTE_NO_SANITIZE_MEMORY
// Tell MemorySanitizer to relax the handling of a given function. All "Use of //
// uninitialized value" warnings from such functions will be suppressed, and all // Tells the MemorySanitizer to relax the handling of a given function. All
// values loaded from memory will be considered fully initialized. // "Use of uninitialized value" warnings from such functions will be suppressed,
// This is similar to the ADDRESS_SANITIZER attribute above, but deals with // and all values loaded from memory will be considered fully initialized.
// initializedness rather than addressability issues. // This attribute is similar to the ADDRESS_SANITIZER attribute above, but deals
// with initialized-ness rather than addressability issues.
// NOTE: MemorySanitizer(msan) is supported by Clang but not GCC. // NOTE: MemorySanitizer(msan) is supported by Clang but not GCC.
#if defined(__GNUC__) && defined(MEMORY_SANITIZER) #if defined(__GNUC__) && defined(MEMORY_SANITIZER)
#define ABSL_ATTRIBUTE_NO_SANITIZE_MEMORY __attribute__((no_sanitize_memory)) #define ABSL_ATTRIBUTE_NO_SANITIZE_MEMORY __attribute__((no_sanitize_memory))
@ -207,8 +247,8 @@
#endif #endif
// ABSL_ATTRIBUTE_NO_SANITIZE_THREAD // ABSL_ATTRIBUTE_NO_SANITIZE_THREAD
// Tell ThreadSanitizer to not instrument a given function. //
// If you are adding this attribute, please cc dynamic-tools@ on the cl. // Tells the ThreadSanitizer to not instrument a given function.
// NOTE: GCC supports ThreadSanitizer(tsan) since 4.8. // NOTE: GCC supports ThreadSanitizer(tsan) since 4.8.
// https://gcc.gnu.org/gcc-4.8/changes.html // https://gcc.gnu.org/gcc-4.8/changes.html
#if defined(__GNUC__) && defined(THREAD_SANITIZER) #if defined(__GNUC__) && defined(THREAD_SANITIZER)
@ -218,7 +258,8 @@
#endif #endif
// ABSL_ATTRIBUTE_NO_SANITIZE_UNDEFINED // ABSL_ATTRIBUTE_NO_SANITIZE_UNDEFINED
// Tell UndefinedSanitizer to ignore a given function. Useful for cases //
// Tells the UndefinedSanitizer to ignore a given function. Useful for cases
// where certain behavior (eg. devision by zero) is being used intentionally. // where certain behavior (eg. devision by zero) is being used intentionally.
// NOTE: GCC supports UndefinedBehaviorSanitizer(ubsan) since 4.9. // NOTE: GCC supports UndefinedBehaviorSanitizer(ubsan) since 4.9.
// https://gcc.gnu.org/gcc-4.9/changes.html // https://gcc.gnu.org/gcc-4.9/changes.html
@ -231,7 +272,8 @@
#endif #endif
// ABSL_ATTRIBUTE_NO_SANITIZE_CFI // ABSL_ATTRIBUTE_NO_SANITIZE_CFI
// Tell ControlFlowIntegrity sanitizer to not instrument a given function. //
// Tells the ControlFlowIntegrity sanitizer to not instrument a given function.
// See https://clang.llvm.org/docs/ControlFlowIntegrity.html for details. // See https://clang.llvm.org/docs/ControlFlowIntegrity.html for details.
#if defined(__GNUC__) && defined(CONTROL_FLOW_INTEGRITY) #if defined(__GNUC__) && defined(CONTROL_FLOW_INTEGRITY)
#define ABSL_ATTRIBUTE_NO_SANITIZE_CFI __attribute__((no_sanitize("cfi"))) #define ABSL_ATTRIBUTE_NO_SANITIZE_CFI __attribute__((no_sanitize("cfi")))
@ -239,33 +281,42 @@
#define ABSL_ATTRIBUTE_NO_SANITIZE_CFI #define ABSL_ATTRIBUTE_NO_SANITIZE_CFI
#endif #endif
// ABSL_ATTRIBUTE_SECTION // ABSL_HAVE_ATTRIBUTE_SECTION
// Labeled sections are not supported on Darwin/iOS. //
// Indicates whether labeled sections are supported. Labeled sections are not
// supported on Darwin/iOS.
#ifdef ABSL_HAVE_ATTRIBUTE_SECTION #ifdef ABSL_HAVE_ATTRIBUTE_SECTION
#error ABSL_HAVE_ATTRIBUTE_SECTION cannot be directly set #error ABSL_HAVE_ATTRIBUTE_SECTION cannot be directly set
#elif (ABSL_HAVE_ATTRIBUTE(section) || \ #elif (ABSL_HAVE_ATTRIBUTE(section) || \
(defined(__GNUC__) && !defined(__clang__))) && \ (defined(__GNUC__) && !defined(__clang__))) && \
!defined(__APPLE__) !defined(__APPLE__)
#define ABSL_HAVE_ATTRIBUTE_SECTION 1 #define ABSL_HAVE_ATTRIBUTE_SECTION 1
// ABSL_ATTRIBUTE_SECTION
// //
// Tell the compiler/linker to put a given function into a section and define // Tells the compiler/linker to put a given function into a section and define
// "__start_ ## name" and "__stop_ ## name" symbols to bracket the section. // `__start_ ## name` and `__stop_ ## name` symbols to bracket the section.
// This functionality is supported by GNU linker. // This functionality is supported by GNU linker. Any function annotated with
// Any function with ABSL_ATTRIBUTE_SECTION must not be inlined, or it will // `ABSL_ATTRIBUTE_SECTION` must not be inlined, or it will be placed into
// be placed into whatever section its caller is placed into. // whatever section its caller is placed into.
// //
#ifndef ABSL_ATTRIBUTE_SECTION #ifndef ABSL_ATTRIBUTE_SECTION
#define ABSL_ATTRIBUTE_SECTION(name) \ #define ABSL_ATTRIBUTE_SECTION(name) \
__attribute__((section(#name))) __attribute__((noinline)) __attribute__((section(#name))) __attribute__((noinline))
#endif #endif
// Tell the compiler/linker to put a given variable into a section and define
// "__start_ ## name" and "__stop_ ## name" symbols to bracket the section. // ABSL_ATTRIBUTE_SECTION_VARIABLE
//
// Tells the compiler/linker to put a given variable into a section and define
// `__start_ ## name` and `__stop_ ## name` symbols to bracket the section.
// This functionality is supported by GNU linker. // This functionality is supported by GNU linker.
#ifndef ABSL_ATTRIBUTE_SECTION_VARIABLE #ifndef ABSL_ATTRIBUTE_SECTION_VARIABLE
#define ABSL_ATTRIBUTE_SECTION_VARIABLE(name) __attribute__((section(#name))) #define ABSL_ATTRIBUTE_SECTION_VARIABLE(name) __attribute__((section(#name)))
#endif #endif
// ABSL_DECLARE_ATTRIBUTE_SECTION_VARS
// //
// Weak section declaration to be used as a global declaration // A weak section declaration to be used as a global declaration
// for ABSL_ATTRIBUTE_SECTION_START|STOP(name) to compile and link // for ABSL_ATTRIBUTE_SECTION_START|STOP(name) to compile and link
// even without functions with ABSL_ATTRIBUTE_SECTION(name). // even without functions with ABSL_ATTRIBUTE_SECTION(name).
// ABSL_DEFINE_ATTRIBUTE_SECTION should be in the exactly one file; it's // ABSL_DEFINE_ATTRIBUTE_SECTION should be in the exactly one file; it's
@ -281,7 +332,9 @@
#define ABSL_DEFINE_ATTRIBUTE_SECTION_VARS(name) #define ABSL_DEFINE_ATTRIBUTE_SECTION_VARS(name)
#endif #endif
// Return void* pointers to start/end of a section of code with // ABSL_ATTRIBUTE_SECTION_START
//
// Returns `void*` pointers to start/end of a section of code with
// functions having ABSL_ATTRIBUTE_SECTION(name). // functions having ABSL_ATTRIBUTE_SECTION(name).
// Returns 0 if no such functions exist. // Returns 0 if no such functions exist.
// One must ABSL_DECLARE_ATTRIBUTE_SECTION_VARS(name) for this to compile and // One must ABSL_DECLARE_ATTRIBUTE_SECTION_VARS(name) for this to compile and
@ -306,6 +359,7 @@
#endif // ABSL_ATTRIBUTE_SECTION #endif // ABSL_ATTRIBUTE_SECTION
// ABSL_ATTRIBUTE_STACK_ALIGN_FOR_OLD_LIBC // ABSL_ATTRIBUTE_STACK_ALIGN_FOR_OLD_LIBC
//
// Support for aligning the stack on 32-bit x86. // Support for aligning the stack on 32-bit x86.
#if ABSL_HAVE_ATTRIBUTE(force_align_arg_pointer) || \ #if ABSL_HAVE_ATTRIBUTE(force_align_arg_pointer) || \
(defined(__GNUC__) && !defined(__clang__)) (defined(__GNUC__) && !defined(__clang__))
@ -326,10 +380,13 @@
#endif #endif
// ABSL_MUST_USE_RESULT // ABSL_MUST_USE_RESULT
// Tell the compiler to warn about unused return values for functions declared //
// Tells the compiler to warn about unused return values for functions declared
// with this macro. The macro must appear as the very first part of a function // with this macro. The macro must appear as the very first part of a function
// declaration or definition: // declaration or definition:
// //
// Example:
//
// ABSL_MUST_USE_RESULT Sprocket* AllocateSprocket(); // ABSL_MUST_USE_RESULT Sprocket* AllocateSprocket();
// //
// This placement has the broadest compatibility with GCC, Clang, and MSVC, with // This placement has the broadest compatibility with GCC, Clang, and MSVC, with
@ -350,10 +407,14 @@
#endif #endif
// ABSL_ATTRIBUTE_HOT, ABSL_ATTRIBUTE_COLD // ABSL_ATTRIBUTE_HOT, ABSL_ATTRIBUTE_COLD
// Tell GCC that a function is hot or cold. GCC can use this information to //
// Tells GCC that a function is hot or cold. GCC can use this information to
// improve static analysis, i.e. a conditional branch to a cold function // improve static analysis, i.e. a conditional branch to a cold function
// is likely to be not-taken. // is likely to be not-taken.
// This annotation is used for function declarations, e.g.: // This annotation is used for function declarations.
//
// Example:
//
// int foo() ABSL_ATTRIBUTE_HOT; // int foo() ABSL_ATTRIBUTE_HOT;
#if ABSL_HAVE_ATTRIBUTE(hot) || (defined(__GNUC__) && !defined(__clang__)) #if ABSL_HAVE_ATTRIBUTE(hot) || (defined(__GNUC__) && !defined(__clang__))
#define ABSL_ATTRIBUTE_HOT __attribute__((hot)) #define ABSL_ATTRIBUTE_HOT __attribute__((hot))
@ -382,12 +443,12 @@
// //
// These attributes only take effect when the following conditions are met: // These attributes only take effect when the following conditions are met:
// //
// - The file/target is built in at least C++11 mode, with a Clang compiler // * The file/target is built in at least C++11 mode, with a Clang compiler
// that supports XRay attributes. // that supports XRay attributes.
// - The file/target is built with the -fxray-instrument flag set for the // * The file/target is built with the -fxray-instrument flag set for the
// Clang/LLVM compiler. // Clang/LLVM compiler.
// - The function is defined in the translation unit (the compiler honors the // * The function is defined in the translation unit (the compiler honors the
// attribute in either the definition or the declaration, and must match). // attribute in either the definition or the declaration, and must match).
// //
// There are cases when, even when building with XRay instrumentation, users // There are cases when, even when building with XRay instrumentation, users
// might want to control specifically which functions are instrumented for a // might want to control specifically which functions are instrumented for a
@ -422,7 +483,8 @@
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// ABSL_ATTRIBUTE_UNUSED // ABSL_ATTRIBUTE_UNUSED
// Prevent the compiler from complaining about or optimizing away variables //
// Prevents the compiler from complaining about or optimizing away variables
// that appear unused. // that appear unused.
#if ABSL_HAVE_ATTRIBUTE(unused) || (defined(__GNUC__) && !defined(__clang__)) #if ABSL_HAVE_ATTRIBUTE(unused) || (defined(__GNUC__) && !defined(__clang__))
#undef ABSL_ATTRIBUTE_UNUSED #undef ABSL_ATTRIBUTE_UNUSED
@ -430,8 +492,10 @@
#else #else
#define ABSL_ATTRIBUTE_UNUSED #define ABSL_ATTRIBUTE_UNUSED
#endif #endif
// ABSL_ATTRIBUTE_INITIAL_EXEC // ABSL_ATTRIBUTE_INITIAL_EXEC
// Tell the compiler to use "initial-exec" mode for a thread-local variable. //
// Tells the compiler to use "initial-exec" mode for a thread-local variable.
// See http://people.redhat.com/drepper/tls.pdf for the gory details. // See http://people.redhat.com/drepper/tls.pdf for the gory details.
#if ABSL_HAVE_ATTRIBUTE(tls_model) || (defined(__GNUC__) && !defined(__clang__)) #if ABSL_HAVE_ATTRIBUTE(tls_model) || (defined(__GNUC__) && !defined(__clang__))
#define ABSL_ATTRIBUTE_INITIAL_EXEC __attribute__((tls_model("initial-exec"))) #define ABSL_ATTRIBUTE_INITIAL_EXEC __attribute__((tls_model("initial-exec")))
@ -440,7 +504,8 @@
#endif #endif
// ABSL_ATTRIBUTE_PACKED // ABSL_ATTRIBUTE_PACKED
// Prevent the compiler from padding a structure to natural alignment //
// Prevents the compiler from padding a structure to natural alignment
#if ABSL_HAVE_ATTRIBUTE(packed) || (defined(__GNUC__) && !defined(__clang__)) #if ABSL_HAVE_ATTRIBUTE(packed) || (defined(__GNUC__) && !defined(__clang__))
#define ABSL_ATTRIBUTE_PACKED __attribute__((__packed__)) #define ABSL_ATTRIBUTE_PACKED __attribute__((__packed__))
#else #else
@ -448,15 +513,16 @@
#endif #endif
// ABSL_CONST_INIT // ABSL_CONST_INIT
// A variable declaration annotated with the ABSL_CONST_INIT attribute will //
// A variable declaration annotated with the `ABSL_CONST_INIT` attribute will
// not compile (on supported platforms) unless the variable has a constant // not compile (on supported platforms) unless the variable has a constant
// initializer. This is useful for variables with static and thread storage // initializer. This is useful for variables with static and thread storage
// duration, because it guarantees that they will not suffer from the so-called // duration, because it guarantees that they will not suffer from the so-called
// "static init order fiasco". // "static init order fiasco".
// //
// Sample usage: // Example:
// //
// ABSL_CONST_INIT static MyType my_var = MakeMyType(...); // ABSL_CONST_INIT static MyType my_var = MakeMyType(...);
// //
// Note that this attribute is redundant if the variable is declared constexpr. // Note that this attribute is redundant if the variable is declared constexpr.
#if ABSL_HAVE_CPP_ATTRIBUTE(clang::require_constant_initialization) #if ABSL_HAVE_CPP_ATTRIBUTE(clang::require_constant_initialization)

View file

@ -25,6 +25,7 @@
#ifndef ABSL_BASE_CALL_ONCE_H_ #ifndef ABSL_BASE_CALL_ONCE_H_
#define ABSL_BASE_CALL_ONCE_H_ #define ABSL_BASE_CALL_ONCE_H_
#include <algorithm>
#include <atomic> #include <atomic>
#include <cstdint> #include <cstdint>
#include <type_traits> #include <type_traits>
@ -32,7 +33,10 @@
#include "absl/base/internal/invoke.h" #include "absl/base/internal/invoke.h"
#include "absl/base/internal/low_level_scheduling.h" #include "absl/base/internal/low_level_scheduling.h"
#include "absl/base/internal/raw_logging.h" #include "absl/base/internal/raw_logging.h"
#include "absl/base/internal/scheduling_mode.h"
#include "absl/base/internal/spinlock_wait.h" #include "absl/base/internal/spinlock_wait.h"
#include "absl/base/macros.h"
#include "absl/base/port.h"
namespace absl { namespace absl {

View file

@ -14,12 +14,12 @@
#include "absl/base/call_once.h" #include "absl/base/call_once.h"
#include <atomic>
#include <thread> #include <thread>
#include <vector>
#include "gtest/gtest.h"
#include "absl/base/thread_annotations.h" #include "absl/base/thread_annotations.h"
#include "absl/synchronization/mutex.h" #include "absl/synchronization/mutex.h"
#include "gtest/gtest.h"
namespace absl { namespace absl {
namespace { namespace {

View file

@ -16,7 +16,6 @@
#include <cstdint> #include <cstdint>
#include "gmock/gmock.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
namespace { namespace {

View file

@ -298,7 +298,7 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
while still letting the compiler elide the functions from the final build. while still letting the compiler elide the functions from the final build.
TODO(delesley) -- The exclusive lock here ignores writes as well, but TODO(delesley) -- The exclusive lock here ignores writes as well, but
allows INGORE_READS_AND_WRITES to work properly. */ allows IGNORE_READS_AND_WRITES to work properly. */
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function" #pragma GCC diagnostic ignored "-Wunused-function"
static inline void StaticAnnotateIgnoreReadsBegin(const char *file, int line) static inline void StaticAnnotateIgnoreReadsBegin(const char *file, int line)

View file

@ -16,8 +16,8 @@
#ifndef ABSL_BASE_INTERNAL_ATOMIC_HOOK_H_ #ifndef ABSL_BASE_INTERNAL_ATOMIC_HOOK_H_
#define ABSL_BASE_INTERNAL_ATOMIC_HOOK_H_ #define ABSL_BASE_INTERNAL_ATOMIC_HOOK_H_
#include <cassert>
#include <atomic> #include <atomic>
#include <cassert>
#include <utility> #include <utility>
namespace absl { namespace absl {

View file

@ -16,13 +16,11 @@
#include <algorithm> #include <algorithm>
#include <cstdint> #include <cstdint>
#include <cstdio>
#include <limits> #include <limits>
#include <random> #include <random>
#include <vector> #include <vector>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "absl/base/casts.h"
#include "absl/base/config.h" #include "absl/base/config.h"
namespace absl { namespace absl {

View file

@ -17,17 +17,19 @@
// This allocator is slow and wasteful of memory; // This allocator is slow and wasteful of memory;
// it should not be used when performance is key. // it should not be used when performance is key.
#include "absl/base/config.h"
#include "absl/base/internal/low_level_alloc.h" #include "absl/base/internal/low_level_alloc.h"
#include "absl/base/config.h"
#include "absl/base/internal/scheduling_mode.h"
#include "absl/base/macros.h"
#include "absl/base/thread_annotations.h"
// LowLevelAlloc requires that the platform support low-level // LowLevelAlloc requires that the platform support low-level
// allocation of virtual memory. Platforms lacking this cannot use // allocation of virtual memory. Platforms lacking this cannot use
// LowLevelAlloc. // LowLevelAlloc.
#ifndef ABSL_LOW_LEVEL_ALLOC_MISSING #ifndef ABSL_LOW_LEVEL_ALLOC_MISSING
#ifndef _WIN32 #ifndef _WIN32
#include <pthread.h>
#include <signal.h> #include <signal.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <unistd.h> #include <unistd.h>
@ -38,8 +40,8 @@
#include <string.h> #include <string.h>
#include <algorithm> #include <algorithm>
#include <atomic> #include <atomic>
#include <cstddef>
#include <cerrno> #include <cerrno>
#include <cstddef>
#include <new> // for placement-new #include <new> // for placement-new
#include "absl/base/dynamic_annotations.h" #include "absl/base/dynamic_annotations.h"

View file

@ -24,8 +24,10 @@
// IWYU pragma: private, include "base/low_level_alloc.h" // IWYU pragma: private, include "base/low_level_alloc.h"
#include <sys/types.h>
#include <cstdint> #include <cstdint>
#include "absl/base/attributes.h"
#include "absl/base/config.h" #include "absl/base/config.h"
// LowLevelAlloc requires that the platform support low-level // LowLevelAlloc requires that the platform support low-level

View file

@ -14,10 +14,12 @@
#include "absl/base/internal/low_level_alloc.h" #include "absl/base/internal/low_level_alloc.h"
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <thread> // NOLINT(build/c++11) #include <thread> // NOLINT(build/c++11)
#include <unordered_map> #include <unordered_map>
#include <utility>
#include "absl/base/internal/malloc_hook.h" #include "absl/base/internal/malloc_hook.h"

View file

@ -30,8 +30,8 @@ extern "C" void __google_enable_rescheduling(bool disable_result);
namespace absl { namespace absl {
namespace base_internal { namespace base_internal {
class SpinLock; // To allow use of SchedulingGuard.
class SchedulingHelper; // To allow use of SchedulingGuard. class SchedulingHelper; // To allow use of SchedulingGuard.
class SpinLock; // To allow use of SchedulingGuard.
// SchedulingGuard // SchedulingGuard
// Provides guard semantics that may be used to disable cooperative rescheduling // Provides guard semantics that may be used to disable cooperative rescheduling

View file

@ -15,15 +15,12 @@
#include "absl/base/internal/malloc_extension.h" #include "absl/base/internal/malloc_extension.h"
#include <assert.h> #include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include <atomic> #include <atomic>
#include <string> #include <string>
#include "absl/base/dynamic_annotations.h" #include "absl/base/dynamic_annotations.h"
#include "absl/base/internal/malloc_extension_c.h" #include "absl/base/internal/malloc_extension_c.h"
#include "absl/base/port.h"
namespace absl { namespace absl {
namespace base_internal { namespace base_internal {

View file

@ -25,14 +25,15 @@
#ifndef ABSL_BASE_INTERNAL_MALLOC_EXTENSION_H_ #ifndef ABSL_BASE_INTERNAL_MALLOC_EXTENSION_H_
#define ABSL_BASE_INTERNAL_MALLOC_EXTENSION_H_ #define ABSL_BASE_INTERNAL_MALLOC_EXTENSION_H_
#include <stddef.h>
#include <stdint.h>
#include <atomic> #include <atomic>
#include <map> #include <map>
#include <memory> #include <memory>
#include <string>
#include <vector> #include <vector>
#include <stddef.h> #include "absl/base/attributes.h"
#include <stdint.h>
#include <string>
#include "absl/base/macros.h" #include "absl/base/macros.h"
#include "absl/base/port.h" #include "absl/base/port.h"
namespace absl { namespace absl {

View file

@ -23,16 +23,17 @@
#undef mremap #undef mremap
#endif #endif
#include "absl/base/internal/malloc_hook.h"
#include <algorithm>
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
#include <algorithm>
#include "absl/base/call_once.h" #include "absl/base/call_once.h"
#include "absl/base/casts.h"
#include "absl/base/internal/malloc_hook.h"
#include "absl/base/internal/malloc_hook_invoke.h" #include "absl/base/internal/malloc_hook_invoke.h"
#include "absl/base/internal/raw_logging.h" #include "absl/base/internal/raw_logging.h"
#include "absl/base/internal/spinlock.h" #include "absl/base/internal/spinlock.h"
#include "absl/base/macros.h"
// __THROW is defined in glibc systems. It means, counter-intuitively, // __THROW is defined in glibc systems. It means, counter-intuitively,
// "This function will never throw an exception." It's an optional // "This function will never throw an exception." It's an optional

View file

@ -12,8 +12,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include <atomic> #include "absl/base/internal/raw_logging.h"
#include <cassert>
#include <stddef.h>
#include <cstdarg> #include <cstdarg>
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
@ -22,8 +23,6 @@
#include "absl/base/config.h" #include "absl/base/config.h"
#include "absl/base/internal/atomic_hook.h" #include "absl/base/internal/atomic_hook.h"
#include "absl/base/internal/log_severity.h" #include "absl/base/internal/log_severity.h"
#include "absl/base/internal/raw_logging.h"
#include "absl/base/port.h"
// We know how to perform low-level writes to stderr in POSIX and Windows. For // We know how to perform low-level writes to stderr in POSIX and Windows. For
// these platforms, we define the token ABSL_LOW_LEVEL_WRITE_SUPPORTED. // these platforms, we define the token ABSL_LOW_LEVEL_WRITE_SUPPORTED.
@ -38,6 +37,7 @@
#if defined(__linux__) || defined(__APPLE__) || defined(__Fuchsia__) || \ #if defined(__linux__) || defined(__APPLE__) || defined(__Fuchsia__) || \
defined(__GENCLAVE__) defined(__GENCLAVE__)
#include <unistd.h> #include <unistd.h>
#define ABSL_HAVE_POSIX_WRITE 1 #define ABSL_HAVE_POSIX_WRITE 1
#define ABSL_LOW_LEVEL_WRITE_SUPPORTED 1 #define ABSL_LOW_LEVEL_WRITE_SUPPORTED 1
#else #else
@ -57,6 +57,7 @@
#ifdef _WIN32 #ifdef _WIN32
#include <io.h> #include <io.h>
#define ABSL_HAVE_RAW_IO 1 #define ABSL_HAVE_RAW_IO 1
#define ABSL_LOW_LEVEL_WRITE_SUPPORTED 1 #define ABSL_LOW_LEVEL_WRITE_SUPPORTED 1
#else #else

View file

@ -19,6 +19,7 @@
#ifndef ABSL_BASE_INTERNAL_RAW_LOGGING_H_ #ifndef ABSL_BASE_INTERNAL_RAW_LOGGING_H_
#define ABSL_BASE_INTERNAL_RAW_LOGGING_H_ #define ABSL_BASE_INTERNAL_RAW_LOGGING_H_
#include "absl/base/attributes.h"
#include "absl/base/internal/log_severity.h" #include "absl/base/internal/log_severity.h"
#include "absl/base/macros.h" #include "absl/base/macros.h"
#include "absl/base/port.h" #include "absl/base/port.h"

View file

@ -16,8 +16,8 @@
#include <algorithm> #include <algorithm>
#include <atomic> #include <atomic>
#include <limits>
#include "absl/base/casts.h"
#include "absl/base/internal/atomic_hook.h" #include "absl/base/internal/atomic_hook.h"
#include "absl/base/internal/cycleclock.h" #include "absl/base/internal/cycleclock.h"
#include "absl/base/internal/spinlock_wait.h" #include "absl/base/internal/spinlock_wait.h"

View file

@ -30,11 +30,17 @@
#ifndef ABSL_BASE_INTERNAL_SPINLOCK_H_ #ifndef ABSL_BASE_INTERNAL_SPINLOCK_H_
#define ABSL_BASE_INTERNAL_SPINLOCK_H_ #define ABSL_BASE_INTERNAL_SPINLOCK_H_
#include <stdint.h>
#include <sys/types.h>
#include <atomic> #include <atomic>
#include "absl/base/attributes.h"
#include "absl/base/dynamic_annotations.h" #include "absl/base/dynamic_annotations.h"
#include "absl/base/internal/low_level_scheduling.h" #include "absl/base/internal/low_level_scheduling.h"
#include "absl/base/internal/raw_logging.h"
#include "absl/base/internal/scheduling_mode.h"
#include "absl/base/internal/tsan_mutex_interface.h" #include "absl/base/internal/tsan_mutex_interface.h"
#include "absl/base/macros.h"
#include "absl/base/port.h" #include "absl/base/port.h"
#include "absl/base/thread_annotations.h" #include "absl/base/thread_annotations.h"

View file

@ -22,6 +22,7 @@
// places listing in //base:spinlock_wait_users. If you need to use it outside // places listing in //base:spinlock_wait_users. If you need to use it outside
// of //base, please request permission to be added to that list. // of //base, please request permission to be added to that list.
#include <stdint.h>
#include <atomic> #include <atomic>
#include "absl/base/internal/scheduling_mode.h" #include "absl/base/internal/scheduling_mode.h"

View file

@ -48,7 +48,6 @@
#include "absl/base/internal/raw_logging.h" #include "absl/base/internal/raw_logging.h"
#include "absl/base/internal/spinlock.h" #include "absl/base/internal/spinlock.h"
#include "absl/base/internal/unscaledcycleclock.h" #include "absl/base/internal/unscaledcycleclock.h"
#include "absl/base/thread_annotations.h"
namespace absl { namespace absl {
namespace base_internal { namespace base_internal {

View file

@ -19,6 +19,7 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "absl/base/internal/spinlock.h" #include "absl/base/internal/spinlock.h"
#include "absl/base/macros.h"
#include "absl/synchronization/internal/per_thread_sem.h" #include "absl/synchronization/internal/per_thread_sem.h"
#include "absl/synchronization/mutex.h" #include "absl/synchronization/mutex.h"

View file

@ -91,6 +91,7 @@ class UnscaledCycleClockWrapperForGetCurrentTime;
namespace base_internal { namespace base_internal {
class CycleClock; class CycleClock;
class UnscaledCycleClockWrapperForInitializeFrequency; class UnscaledCycleClockWrapperForInitializeFrequency;
class UnscaledCycleClock { class UnscaledCycleClock {
private: private:
UnscaledCycleClock() = delete; UnscaledCycleClock() = delete;

View file

@ -17,6 +17,7 @@
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility>
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"

View file

@ -24,8 +24,10 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "absl/base/internal/low_level_scheduling.h" #include "absl/base/internal/low_level_scheduling.h"
#include "absl/base/internal/scheduling_mode.h"
#include "absl/base/internal/spinlock.h" #include "absl/base/internal/spinlock.h"
#include "absl/base/internal/sysinfo.h" #include "absl/base/internal/sysinfo.h"
#include "absl/base/macros.h"
#include "absl/synchronization/blocking_counter.h" #include "absl/synchronization/blocking_counter.h"
#include "absl/synchronization/notification.h" #include "absl/synchronization/notification.h"

View file

@ -18,7 +18,6 @@
#include <new> #include <new>
#include <stdexcept> #include <stdexcept>
#include "gmock/gmock.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
namespace { namespace {

View file

@ -78,10 +78,7 @@ namespace absl {
// uint64_t i = v // Error // uint64_t i = v // Error
// uint64_t i = static_cast<uint64_t>(v) // OK // uint64_t i = static_cast<uint64_t>(v) // OK
// //
// NOTE: the alignment requirement of `uint128` is due to change, so users class alignas(16) uint128 {
// should take care to avoid depending on the current 8 byte alignment.
// TODO(strel) Remove alignment note above once alignof(uint128) becomes 16.
class uint128 {
public: public:
uint128() = default; uint128() = default;

View file

@ -79,6 +79,18 @@ cc_library(
], ],
) )
cc_test(
name = "barrier_test",
size = "small",
srcs = ["barrier_test.cc"],
copts = ABSL_TEST_COPTS,
deps = [
":synchronization",
"//absl/time",
"@com_google_googletest//:gtest_main",
],
)
cc_test( cc_test(
name = "blocking_counter_test", name = "blocking_counter_test",
size = "small", size = "small",

View file

@ -0,0 +1,75 @@
// Copyright 2017 The Abseil Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "absl/synchronization/barrier.h"
#include <thread> // NOLINT(build/c++11)
#include <vector>
#include "gtest/gtest.h"
#include "absl/synchronization/mutex.h"
#include "absl/time/clock.h"
TEST(Barrier, SanityTest) {
constexpr int kNumThreads = 10;
absl::Barrier* barrier = new absl::Barrier(kNumThreads);
absl::Mutex mutex;
int counter = 0; // Guarded by mutex.
auto thread_func = [&] {
if (barrier->Block()) {
// This thread is the last thread to reach the barrier so it is
// responsible for deleting it.
delete barrier;
}
// Increment the counter.
absl::MutexLock lock(&mutex);
++counter;
};
// Start (kNumThreads - 1) threads running thread_func.
std::vector<std::thread> threads;
for (int i = 0; i < kNumThreads - 1; ++i) {
threads.push_back(std::thread(thread_func));
}
// Give (kNumThreads - 1) threads a chance to reach the barrier.
// This test assumes at least one thread will have run after the
// sleep has elapsed. Sleeping in a test is usually bad form, but we
// need to make sure that we are testing the barrier instead of some
// other synchronization method.
absl::SleepFor(absl::Seconds(1));
// The counter should still be zero since no thread should have
// been able to pass the barrier yet.
{
absl::MutexLock lock(&mutex);
EXPECT_EQ(counter, 0);
}
// Start 1 more thread. This should make all threads pass the barrier.
threads.push_back(std::thread(thread_func));
// All threads should now be able to proceed and finish.
for (auto& thread : threads) {
thread.join();
}
// All threads should now have incremented the counter.
absl::MutexLock lock(&mutex);
EXPECT_EQ(counter, kNumThreads);
}

View file

@ -1527,4 +1527,5 @@ TEST(Duration, FormatParseRoundTrip) {
#undef TEST_PARSE_ROUNDTRIP #undef TEST_PARSE_ROUNDTRIP
} }
} // namespace } // namespace

View file

@ -427,4 +427,5 @@ TEST(FormatParse, RoundTripDistantPast) {
<< s << ": " << err; << s << ": " << err;
EXPECT_EQ(in, out); EXPECT_EQ(in, out);
} }
} // namespace } // namespace

View file

@ -439,6 +439,33 @@ struct is_constructible_convertible_assignable_from_optional
// for checking whether an expression is convertible to bool. // for checking whether an expression is convertible to bool.
bool convertible_to_bool(bool); bool convertible_to_bool(bool);
// Base class for std::hash<absl::optional<T>>:
// If std::hash<std::remove_const_t<T>> is enabled, it provides operator() to
// compute the hash; Otherwise, it is disabled.
// Reference N4659 23.14.15 [unord.hash].
template <typename T, typename = size_t>
struct optional_hash_base {
optional_hash_base() = delete;
optional_hash_base(const optional_hash_base&) = delete;
optional_hash_base(optional_hash_base&&) = delete;
optional_hash_base& operator=(const optional_hash_base&) = delete;
optional_hash_base& operator=(optional_hash_base&&) = delete;
};
template <typename T>
struct optional_hash_base<T, decltype(std::hash<absl::remove_const_t<T> >()(
std::declval<absl::remove_const_t<T> >()))> {
using argument_type = absl::optional<T>;
using result_type = size_t;
size_t operator()(const absl::optional<T>& opt) const {
if (opt) {
return std::hash<absl::remove_const_t<T> >()(*opt);
} else {
return static_cast<size_t>(0x297814aaad196e6dULL);
}
}
};
} // namespace optional_internal } // namespace optional_internal
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -1072,15 +1099,8 @@ namespace std {
// std::hash specialization for absl::optional. // std::hash specialization for absl::optional.
template <typename T> template <typename T>
struct hash<absl::optional<T>> { struct hash<absl::optional<T> >
size_t operator()(const absl::optional<T>& opt) const { : absl::optional_internal::optional_hash_base<T> {};
if (opt) {
return hash<T>()(*opt);
} else {
return static_cast<size_t>(0x297814aaad196e6dULL);
}
}
};
} // namespace std } // namespace std

View file

@ -24,6 +24,17 @@
#include "absl/meta/type_traits.h" #include "absl/meta/type_traits.h"
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
struct Hashable {};
namespace std {
template <>
struct hash<Hashable> {
size_t operator()(const Hashable&) { return 0; }
};
} // namespace std
struct NonHashable {};
namespace { namespace {
std::string TypeQuals(std::string&) { return "&"; } std::string TypeQuals(std::string&) { return "&"; }
@ -1434,6 +1445,17 @@ TEST(optionalTest, ValueType) {
(std::is_same<absl::optional<int>::value_type, absl::nullopt_t>::value)); (std::is_same<absl::optional<int>::value_type, absl::nullopt_t>::value));
} }
template <typename T>
struct is_hash_enabled_for {
template <typename U, typename = decltype(std::hash<U>()(std::declval<U>()))>
static std::true_type test(int);
template <typename U>
static std::false_type test(...);
static constexpr bool value = decltype(test<T>(0))::value;
};
TEST(optionalTest, Hash) { TEST(optionalTest, Hash) {
std::hash<absl::optional<int>> hash; std::hash<absl::optional<int>> hash;
std::set<size_t> hashcodes; std::set<size_t> hashcodes;
@ -1442,6 +1464,34 @@ TEST(optionalTest, Hash) {
hashcodes.insert(hash(i)); hashcodes.insert(hash(i));
} }
EXPECT_GT(hashcodes.size(), 90); EXPECT_GT(hashcodes.size(), 90);
static_assert(is_hash_enabled_for<absl::optional<int>>::value, "");
static_assert(is_hash_enabled_for<absl::optional<Hashable>>::value, "");
#if defined(_MSC_VER) || (defined(_LIBCPP_VERSION) && \
_LIBCPP_VERSION < 4000 && _LIBCPP_STD_VER > 11)
// For MSVC and libc++ (< 4.0 and c++14), std::hash primary template has a
// static_assert to catch any user-defined type that doesn't provide a hash
// specialization. So instantiating std::hash<absl::optional<T>> will result
// in a hard error which is not SFINAE friendly.
#define ABSL_STD_HASH_NOT_SFINAE_FRIENDLY 1
#endif
#ifndef ABSL_STD_HASH_NOT_SFINAE_FRIENDLY
static_assert(!is_hash_enabled_for<absl::optional<NonHashable>>::value, "");
#endif
// libstdc++ std::optional is missing remove_const_t, i.e. it's using
// std::hash<T> rather than std::hash<std::remove_const_t<T>>.
// Reference: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82262
#ifndef __GLIBCXX__
static_assert(is_hash_enabled_for<absl::optional<const int>>::value, "");
static_assert(is_hash_enabled_for<absl::optional<const Hashable>>::value, "");
std::hash<absl::optional<const int>> c_hash;
for (int i = 0; i < 100; ++i) {
EXPECT_EQ(hash(i), c_hash(i));
}
#endif
} }
struct MoveMeNoThrow { struct MoveMeNoThrow {

View file

@ -12,36 +12,39 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
// //
// This header file contains C++11 versions of standard <utility> header
// absl/utility:utility is an extension of the <utility> header // abstractions available within C++14 and C++17, and are designed to be drop-in
// replacement for code compliant with C++14 and C++17.
// //
// It provides stand-ins for C++14's std::integer_sequence and // The following abstractions are defined:
// related utilities. They are intended to be exactly equivalent.
// - integer_sequence<T, Ints...> == std::integer_sequence<T, Ints...>
// - index_sequence<Ints...> == std::index_sequence<Ints...>
// - make_integer_sequence<T, N> == std::make_integer_sequence<T, N>
// - make_index_sequence<N> == std::make_index_sequence<N>
// - index_sequence_for<Ts...> == std::index_sequence_for<Ts...>
// //
// It also provides the tag types in_place_t, in_place_type_t, and // * integer_sequence<T, Ints...> == std::integer_sequence<T, Ints...>
// in_place_index_t, as well as the constant in_place, and constexpr std::move // * index_sequence<Ints...> == std::index_sequence<Ints...>
// and std::forward impolementations in C++11. // * make_integer_sequence<T, N> == std::make_integer_sequence<T, N>
// * make_index_sequence<N> == std::make_index_sequence<N>
// * index_sequence_for<Ts...> == std::index_sequence_for<Ts...>
//
// This header file also provides the tag types `in_place_t`, `in_place_type_t`,
// and `in_place_index_t`, as well as the constant `in_place`, and
// `constexpr` `std::move()` and `std::forward()` implementations in C++11.
// //
// References: // References:
//
// http://en.cppreference.com/w/cpp/utility/integer_sequence // http://en.cppreference.com/w/cpp/utility/integer_sequence
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3658.html // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3658.html
// //
//
// Example: // Example:
// // Unpack a tuple for use as a function call's argument list. // // Unpack a tuple for use as a function call's argument list.
// //
// template <typename F, typename Tup, size_t... Is> // template <typename F, typename Tup, size_t... Is>
// auto Impl(F f, const Tup& tup, index_sequence<Is...>) // auto Impl(F f, const Tup& tup, absl::index_sequence<Is...>)
// -> decltype(f(std::get<Is>(tup) ...)) { // -> decltype(f(std::get<Is>(tup) ...)) {
// return f(std::get<Is>(tup) ...); // return f(std::get<Is>(tup) ...);
// } // }
// //
// template <typename Tup> // template <typename Tup>
// using TupIdxSeq = make_index_sequence<std::tuple_size<Tup>::value>; // using TupIdxSeq = absl::make_index_sequence<std::tuple_size<Tup>::value>;
// //
// template <typename F, typename Tup> // template <typename F, typename Tup>
// auto ApplyFromTuple(F f, const Tup& tup) // auto ApplyFromTuple(F f, const Tup& tup)
@ -60,23 +63,36 @@
namespace absl { namespace absl {
// Equivalent to std::integer_sequence. // integer_sequence
// //
// Function templates can deduce compile-time integer sequences by accepting // Class template representing a compile-time integer sequence. An instantiation
// an argument of integer_sequence<T, Ints...>. This is a common need when // of `integer_sequence<T, Ints...>` has a sequence of integers encoded in its
// working with C++11 variadic templates. // type through its template arguments (which is a common need when
// working with C++11 variadic templates). `absl::integer_sequence` is designed
// to be a drop-in replacement for C++14's `std::integer_sequence`.
// //
// T - the integer type of the sequence elements // Example:
// ...Ints - a parameter pack of T values representing the sequence //
// template< class T, T... Ints >
// void user_function(integer_sequence<T, Ints...>);
//
// int main()
// {
// // user_function's `T` will be deduced to `int` and `Ints...`
// // will be deduced to `0, 1, 2, 3, 4`.
// user_function(make_integer_sequence<int, 5>());
// }
template <typename T, T... Ints> template <typename T, T... Ints>
struct integer_sequence { struct integer_sequence {
using value_type = T; using value_type = T;
static constexpr size_t size() noexcept { return sizeof...(Ints); } static constexpr size_t size() noexcept { return sizeof...(Ints); }
}; };
// Equivalent to std::index_sequence. // index_sequence
// //
// Alias for an integer_sequence of size_t. // A helper template for an `integer_sequence` of `size_t`,
// `absl::index_sequence` is designed to be a drop-in replacement for C++14's
// `std::index_sequence`.
template <size_t... Ints> template <size_t... Ints>
using index_sequence = integer_sequence<size_t, Ints...>; using index_sequence = integer_sequence<size_t, Ints...>;
@ -113,21 +129,27 @@ struct Gen<T, 0> {
// Compile-time sequences of integers // Compile-time sequences of integers
// Equivalent to std::make_integer_sequence. // make_integer_sequence
// //
// make_integer_sequence<int, N> is integer_sequence<int, 0, 1, ..., N-1>; // This template alias is equivalent to
// `integer_sequence<int, 0, 1, ..., N-1>`, and is designed to be a drop-in
// replacement for C++14's `std::make_integer_sequence`.
template <typename T, T N> template <typename T, T N>
using make_integer_sequence = typename utility_internal::Gen<T, N>::type; using make_integer_sequence = typename utility_internal::Gen<T, N>::type;
// Equivalent to std::make_index_sequence. // make_index_sequence
// //
// make_index_sequence<N> is index_sequence<0, 1, ..., N-1>; // This template alias is equivalent to `index_sequence<0, 1, ..., N-1>`,
// and is designed to be a drop-in replacement for C++14's
// `std::make_index_sequence`.
template <size_t N> template <size_t N>
using make_index_sequence = make_integer_sequence<size_t, N>; using make_index_sequence = make_integer_sequence<size_t, N>;
// Equivalent to std::index_sequence_for. // index_sequence_for
// //
// Convert a typename pack into an index sequence of the same length. // Converts a typename pack into an index sequence of the same length, and
// is designed to be a drop-in replacement for C++14's
// `std::index_sequence_for()`
template <typename... Ts> template <typename... Ts>
using index_sequence_for = make_index_sequence<sizeof...(Ts)>; using index_sequence_for = make_index_sequence<sizeof...(Ts)>;
@ -140,8 +162,11 @@ using std::in_place;
#else // ABSL_HAVE_STD_OPTIONAL #else // ABSL_HAVE_STD_OPTIONAL
// Tag type used in order to specify in-place construction, such as with // in_place_t
// absl::optional. //
// Tag type used to specify in-place construction, such as with
// `absl::optional`, designed to be a drop-in replacement for C++17's
// `std::in_place_t`.
struct in_place_t {}; struct in_place_t {};
extern const in_place_t in_place; extern const in_place_t in_place;
@ -150,22 +175,39 @@ extern const in_place_t in_place;
#ifdef ABSL_HAVE_STD_ANY #ifdef ABSL_HAVE_STD_ANY
using std::in_place_type_t; using std::in_place_type_t;
#else #else
// Tag types used for in-place construction when the type to construct needs to
// be specified, such as with absl::variant and absl::any. // in_place_type_t
//
// Tag type used for in-place construction when the type to construct needs to
// be specified, such as with `absl::any`, designed to be a drop-in replacement
// for C++17's `std::in_place_type_t`.
template <typename T> template <typename T>
struct in_place_type_t {}; struct in_place_type_t {};
#endif // ABSL_HAVE_STD_ANY #endif // ABSL_HAVE_STD_ANY
// in_place_index_t
//
// Tag type used for in-place construction when the type to construct needs to
// be specified, such as with `absl::any`, designed to be a drop-in replacement
// for C++17's `std::in_place_index_t`.
template <size_t I> template <size_t I>
struct in_place_index_t {}; struct in_place_index_t {};
// Constexpr move and forward // Constexpr move and forward
// move()
//
// A constexpr version of `std::move()`, designed to be a drop-in replacement
// for C++14's `std::move()`.
template <typename T> template <typename T>
constexpr absl::remove_reference_t<T>&& move(T&& t) noexcept { constexpr absl::remove_reference_t<T>&& move(T&& t) noexcept {
return static_cast<absl::remove_reference_t<T>&&>(t); return static_cast<absl::remove_reference_t<T>&&>(t);
} }
// forward()
//
// A constexpr version of `std::forward()`, designed to be a drop-in replacement
// for C++14's `std::forward()`.
template <typename T> template <typename T>
constexpr T&& forward( constexpr T&& forward(
absl::remove_reference_t<T>& t) noexcept { // NOLINT(runtime/references) absl::remove_reference_t<T>& t) noexcept { // NOLINT(runtime/references)