From c1061b7362471ddb7cae26c430f8112b0b94bb83 Mon Sep 17 00:00:00 2001 From: zxu Date: Fri, 13 Apr 2018 14:30:10 -0400 Subject: carbon-copy of the `optional`-relevant src from abseil (#1083) --- .../abseil-cpp/absl/base/inline_variable_test.cc | 62 ++ .../abseil-cpp/absl/base/inline_variable_test_a.cc | 25 + .../abseil-cpp/absl/base/inline_variable_test_b.cc | 25 + .../abseil-cpp/absl/base/internal/identity.h | 33 + .../absl/base/internal/inline_variable.h | 107 ++ .../absl/base/internal/inline_variable_testing.h | 44 + .../abseil-cpp/absl/types/bad_optional_access.cc | 42 + .../abseil-cpp/absl/types/bad_optional_access.h | 37 + .../third_party/abseil-cpp/absl/types/optional.cc | 24 + .../third_party/abseil-cpp/absl/types/optional.h | 1128 ++++++++++++++++++++ .../third_party/abseil-cpp/absl/utility/utility.h | 264 +++++ 11 files changed, 1791 insertions(+) create mode 100644 Firestore/third_party/abseil-cpp/absl/base/inline_variable_test.cc create mode 100644 Firestore/third_party/abseil-cpp/absl/base/inline_variable_test_a.cc create mode 100644 Firestore/third_party/abseil-cpp/absl/base/inline_variable_test_b.cc create mode 100644 Firestore/third_party/abseil-cpp/absl/base/internal/identity.h create mode 100644 Firestore/third_party/abseil-cpp/absl/base/internal/inline_variable.h create mode 100644 Firestore/third_party/abseil-cpp/absl/base/internal/inline_variable_testing.h create mode 100644 Firestore/third_party/abseil-cpp/absl/types/bad_optional_access.cc create mode 100644 Firestore/third_party/abseil-cpp/absl/types/bad_optional_access.h create mode 100644 Firestore/third_party/abseil-cpp/absl/types/optional.cc create mode 100644 Firestore/third_party/abseil-cpp/absl/types/optional.h create mode 100644 Firestore/third_party/abseil-cpp/absl/utility/utility.h (limited to 'Firestore/third_party') diff --git a/Firestore/third_party/abseil-cpp/absl/base/inline_variable_test.cc b/Firestore/third_party/abseil-cpp/absl/base/inline_variable_test.cc new file mode 100644 index 0000000..5499189 --- /dev/null +++ b/Firestore/third_party/abseil-cpp/absl/base/inline_variable_test.cc @@ -0,0 +1,62 @@ +// 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 + +#include "absl/base/internal/inline_variable.h" +#include "absl/base/internal/inline_variable_testing.h" + +#include "gtest/gtest.h" + +namespace absl { +namespace inline_variable_testing_internal { +namespace { + +TEST(InlineVariableTest, Constexpr) { + static_assert(inline_variable_foo.value == 5, ""); + static_assert(other_inline_variable_foo.value == 5, ""); + static_assert(inline_variable_int == 5, ""); + static_assert(other_inline_variable_int == 5, ""); +} + +TEST(InlineVariableTest, DefaultConstructedIdentityEquality) { + EXPECT_EQ(get_foo_a().value, 5); + EXPECT_EQ(get_foo_b().value, 5); + EXPECT_EQ(&get_foo_a(), &get_foo_b()); +} + +TEST(InlineVariableTest, DefaultConstructedIdentityInequality) { + EXPECT_NE(&inline_variable_foo, &other_inline_variable_foo); +} + +TEST(InlineVariableTest, InitializedIdentityEquality) { + EXPECT_EQ(get_int_a(), 5); + EXPECT_EQ(get_int_b(), 5); + EXPECT_EQ(&get_int_a(), &get_int_b()); +} + +TEST(InlineVariableTest, InitializedIdentityInequality) { + EXPECT_NE(&inline_variable_int, &other_inline_variable_int); +} + +TEST(InlineVariableTest, FunPtrType) { + static_assert( + std::is_same::type>::value, + ""); +} + +} // namespace +} // namespace inline_variable_testing_internal +} // namespace absl diff --git a/Firestore/third_party/abseil-cpp/absl/base/inline_variable_test_a.cc b/Firestore/third_party/abseil-cpp/absl/base/inline_variable_test_a.cc new file mode 100644 index 0000000..a3bf3b6 --- /dev/null +++ b/Firestore/third_party/abseil-cpp/absl/base/inline_variable_test_a.cc @@ -0,0 +1,25 @@ +// 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/base/internal/inline_variable_testing.h" + +namespace absl { +namespace inline_variable_testing_internal { + +const Foo& get_foo_a() { return inline_variable_foo; } + +const int& get_int_a() { return inline_variable_int; } + +} // namespace inline_variable_testing_internal +} // namespace absl diff --git a/Firestore/third_party/abseil-cpp/absl/base/inline_variable_test_b.cc b/Firestore/third_party/abseil-cpp/absl/base/inline_variable_test_b.cc new file mode 100644 index 0000000..b4b9393 --- /dev/null +++ b/Firestore/third_party/abseil-cpp/absl/base/inline_variable_test_b.cc @@ -0,0 +1,25 @@ +// 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/base/internal/inline_variable_testing.h" + +namespace absl { +namespace inline_variable_testing_internal { + +const Foo& get_foo_b() { return inline_variable_foo; } + +const int& get_int_b() { return inline_variable_int; } + +} // namespace inline_variable_testing_internal +} // namespace absl diff --git a/Firestore/third_party/abseil-cpp/absl/base/internal/identity.h b/Firestore/third_party/abseil-cpp/absl/base/internal/identity.h new file mode 100644 index 0000000..a6734b4 --- /dev/null +++ b/Firestore/third_party/abseil-cpp/absl/base/internal/identity.h @@ -0,0 +1,33 @@ +// 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. +// + +#ifndef ABSL_BASE_INTERNAL_IDENTITY_H_ +#define ABSL_BASE_INTERNAL_IDENTITY_H_ + +namespace absl { +namespace internal { + +template +struct identity { + typedef T type; +}; + +template +using identity_t = typename identity::type; + +} // namespace internal +} // namespace absl + +#endif // ABSL_BASE_INTERNAL_IDENTITY_H_ diff --git a/Firestore/third_party/abseil-cpp/absl/base/internal/inline_variable.h b/Firestore/third_party/abseil-cpp/absl/base/internal/inline_variable.h new file mode 100644 index 0000000..f7bb8c5 --- /dev/null +++ b/Firestore/third_party/abseil-cpp/absl/base/internal/inline_variable.h @@ -0,0 +1,107 @@ +// 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. + +#ifndef ABSL_BASE_INTERNAL_INLINE_VARIABLE_EMULATION_H_ +#define ABSL_BASE_INTERNAL_INLINE_VARIABLE_EMULATION_H_ + +#include + +#include "absl/base/internal/identity.h" + +// File: +// This file define a macro that allows the creation of or emulation of C++17 +// inline variables based on whether or not the feature is supported. + +//////////////////////////////////////////////////////////////////////////////// +// Macro: ABSL_INTERNAL_INLINE_CONSTEXPR(type, name, init) +// +// Description: +// Expands to the equivalent of an inline constexpr instance of the specified +// `type` and `name`, initialized to the value `init`. If the compiler being +// used is detected as supporting actual inline variables as a language +// feature, then the macro expands to an actual inline variable definition. +// +// Requires: +// `type` is a type that is usable in an extern variable declaration. +// +// Requires: `name` is a valid identifier +// +// Requires: +// `init` is an expression that can be used in the following definition: +// constexpr type name = init; +// +// Usage: +// +// // Equivalent to: `inline constexpr size_t variant_npos = -1;` +// ABSL_INTERNAL_INLINE_CONSTEXPR(size_t, variant_npos, -1); +// +// Differences in implementation: +// For a direct, language-level inline variable, decltype(name) will be the +// type that was specified along with const qualification, whereas for +// emulated inline variables, decltype(name) may be different (in practice +// it will likely be a reference type). +//////////////////////////////////////////////////////////////////////////////// + +#ifdef __cpp_inline_variables + +// Clang's -Wmissing-variable-declarations option erroneously warned that +// inline constexpr objects need to be pre-declared. This has now been fixed, +// but we will need to support this workaround for people building with older +// versions of clang. +// +// Bug: https://bugs.llvm.org/show_bug.cgi?id=35862 +// +// Note: +// identity_t is used here so that the const and name are in the +// appropriate place for pointer types, reference types, function pointer +// types, etc.. +#if defined(__clang__) +#define ABSL_INTERNAL_EXTERN_DECL(type, name) \ + extern const ::absl::internal::identity_t name; +#else // Otherwise, just define the macro to do nothing. +#define ABSL_INTERNAL_EXTERN_DECL(type, name) +#endif // defined(__clang__) + +// See above comment at top of file for details. +#define ABSL_INTERNAL_INLINE_CONSTEXPR(type, name, init) \ + ABSL_INTERNAL_EXTERN_DECL(type, name) \ + inline constexpr ::absl::internal::identity_t name = init + +#else + +// See above comment at top of file for details. +// +// Note: +// identity_t is used here so that the const and name are in the +// appropriate place for pointer types, reference types, function pointer +// types, etc.. +#define ABSL_INTERNAL_INLINE_CONSTEXPR(var_type, name, init) \ + template \ + struct AbslInternalInlineVariableHolder##name { \ + static constexpr ::absl::internal::identity_t kInstance = init; \ + }; \ + \ + template \ + constexpr ::absl::internal::identity_t \ + AbslInternalInlineVariableHolder##name::kInstance; \ + \ + static constexpr const ::absl::internal::identity_t& \ + name = /* NOLINT */ \ + AbslInternalInlineVariableHolder##name<>::kInstance; \ + static_assert(sizeof(void (*)(decltype(name))) != 0, \ + "Silence unused variable warnings.") + +#endif // __cpp_inline_variables + +#endif // ABSL_BASE_INTERNAL_INLINE_VARIABLE_EMULATION_H_ diff --git a/Firestore/third_party/abseil-cpp/absl/base/internal/inline_variable_testing.h b/Firestore/third_party/abseil-cpp/absl/base/internal/inline_variable_testing.h new file mode 100644 index 0000000..a0dd2bb --- /dev/null +++ b/Firestore/third_party/abseil-cpp/absl/base/internal/inline_variable_testing.h @@ -0,0 +1,44 @@ +// 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. + +#ifndef ABSL_BASE_INLINE_VARIABLE_TESTING_H_ +#define ABSL_BASE_INLINE_VARIABLE_TESTING_H_ + +#include "absl/base/internal/inline_variable.h" + +namespace absl { +namespace inline_variable_testing_internal { + +struct Foo { + int value = 5; +}; + +ABSL_INTERNAL_INLINE_CONSTEXPR(Foo, inline_variable_foo, {}); +ABSL_INTERNAL_INLINE_CONSTEXPR(Foo, other_inline_variable_foo, {}); + +ABSL_INTERNAL_INLINE_CONSTEXPR(int, inline_variable_int, 5); +ABSL_INTERNAL_INLINE_CONSTEXPR(int, other_inline_variable_int, 5); + +ABSL_INTERNAL_INLINE_CONSTEXPR(void(*)(), inline_variable_fun_ptr, nullptr); + +const Foo& get_foo_a(); +const Foo& get_foo_b(); + +const int& get_int_a(); +const int& get_int_b(); + +} // namespace inline_variable_testing_internal +} // namespace absl + +#endif // ABSL_BASE_INLINE_VARIABLE_TESTING_H_ diff --git a/Firestore/third_party/abseil-cpp/absl/types/bad_optional_access.cc b/Firestore/third_party/abseil-cpp/absl/types/bad_optional_access.cc new file mode 100644 index 0000000..6bc67df --- /dev/null +++ b/Firestore/third_party/abseil-cpp/absl/types/bad_optional_access.cc @@ -0,0 +1,42 @@ +// 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/types/bad_optional_access.h" + +#include + +#include "absl/base/config.h" +#include "absl/base/internal/raw_logging.h" + +namespace absl { + +bad_optional_access::~bad_optional_access() = default; + +const char* bad_optional_access::what() const noexcept { + return "optional has no value"; +} + +namespace optional_internal { + +void throw_bad_optional_access() { +#ifdef ABSL_HAVE_EXCEPTIONS + throw bad_optional_access(); +#else + ABSL_RAW_LOG(FATAL, "Bad optional access"); + abort(); +#endif +} + +} // namespace optional_internal +} // namespace absl diff --git a/Firestore/third_party/abseil-cpp/absl/types/bad_optional_access.h b/Firestore/third_party/abseil-cpp/absl/types/bad_optional_access.h new file mode 100644 index 0000000..c4c7444 --- /dev/null +++ b/Firestore/third_party/abseil-cpp/absl/types/bad_optional_access.h @@ -0,0 +1,37 @@ +// 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. + +#ifndef ABSL_TYPES_BAD_OPTIONAL_ACCESS_H_ +#define ABSL_TYPES_BAD_OPTIONAL_ACCESS_H_ + +#include + +namespace absl { + +class bad_optional_access : public std::exception { + public: + bad_optional_access() = default; + ~bad_optional_access() override; + const char* what() const noexcept override; +}; + +namespace optional_internal { + +// throw delegator +[[noreturn]] void throw_bad_optional_access(); + +} // namespace optional_internal +} // namespace absl + +#endif // ABSL_TYPES_BAD_OPTIONAL_ACCESS_H_ diff --git a/Firestore/third_party/abseil-cpp/absl/types/optional.cc b/Firestore/third_party/abseil-cpp/absl/types/optional.cc new file mode 100644 index 0000000..ef27290 --- /dev/null +++ b/Firestore/third_party/abseil-cpp/absl/types/optional.cc @@ -0,0 +1,24 @@ +// 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/types/optional.h" + +#ifndef ABSL_HAVE_STD_OPTIONAL +namespace absl { + +nullopt_t::init_t nullopt_t::init; +extern const nullopt_t nullopt{nullopt_t::init}; + +} // namespace absl +#endif // ABSL_HAVE_STD_OPTIONAL diff --git a/Firestore/third_party/abseil-cpp/absl/types/optional.h b/Firestore/third_party/abseil-cpp/absl/types/optional.h new file mode 100644 index 0000000..9313fd2 --- /dev/null +++ b/Firestore/third_party/abseil-cpp/absl/types/optional.h @@ -0,0 +1,1128 @@ +// +// 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. +// +// ----------------------------------------------------------------------------- +// optional.h +// ----------------------------------------------------------------------------- +// +// This header file defines the `absl::optional` type for holding a value which +// may or may not be present. This type is useful for providing value semantics +// for operations that may either wish to return or hold "something-or-nothing". +// +// Example: +// +// // A common way to signal operation failure is to provide an output +// // parameter and a bool return type: +// bool AcquireResource(const Input&, Resource * out); +// +// // Providing an absl::optional return type provides a cleaner API: +// absl::optional AcquireResource(const Input&); +// +// `absl::optional` is a C++11 compatible version of the C++17 `std::optional` +// abstraction and is designed to be a drop-in replacement for code compliant +// with C++17. +#ifndef ABSL_TYPES_OPTIONAL_H_ +#define ABSL_TYPES_OPTIONAL_H_ + +#include "absl/base/config.h" +#include "absl/utility/utility.h" + +#ifdef ABSL_HAVE_STD_OPTIONAL + +#include + +namespace absl { +using std::bad_optional_access; +using std::optional; +using std::make_optional; +using std::nullopt_t; +using std::nullopt; +} + +#else // ABSL_HAVE_STD_OPTIONAL + +#include +#include +#include +#include +#include +#include + +#include "absl/memory/memory.h" +#include "absl/meta/type_traits.h" +#include "absl/types/bad_optional_access.h" + +// ABSL_OPTIONAL_USE_INHERITING_CONSTRUCTORS +// +// Inheriting constructors is supported in GCC 4.8+, Clang 3.3+ and MSVC 2015. +// __cpp_inheriting_constructors is a predefined macro and a recommended way to +// check for this language feature, but GCC doesn't support it until 5.0 and +// Clang doesn't support it until 3.6. +// Also, MSVC 2015 has a bug: it doesn't inherit the constexpr template +// constructor. For example, the following code won't work on MSVC 2015 Update3: +// struct Base { +// int t; +// template +// constexpr Base(T t_) : t(t_) {} +// }; +// struct Foo : Base { +// using Base::Base; +// } +// constexpr Foo foo(0); // doesn't work on MSVC 2015 +#if defined(__clang__) +#if __has_feature(cxx_inheriting_constructors) +#define ABSL_OPTIONAL_USE_INHERITING_CONSTRUCTORS 1 +#endif +#elif (defined(__GNUC__) && \ + (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 8)) || \ + (__cpp_inheriting_constructors >= 200802) || \ + (defined(_MSC_VER) && _MSC_VER >= 1910) +#define ABSL_OPTIONAL_USE_INHERITING_CONSTRUCTORS 1 +#endif + +namespace absl { + +// optional +// +// A value of type `absl::optional` holds either a value of `T` or an +// "empty" value. When it holds a value of `T`, it stores it as a direct +// sub-object, so `sizeof(optional)` is approximately +// `sizeof(T) + sizeof(bool)`. +// +// This implementation is based on the specification in the latest draft of the +// C++17 `std::optional` specification as of May 2017, section 20.6. +// +// Differences between `absl::optional` and `std::optional` include: +// +// * `constexpr` is not used for non-const member functions. +// (dependency on some differences between C++11 and C++14.) +// * `absl::nullopt` and `absl::in_place` are not declared `constexpr`. We +// need the inline variable support in C++17 for external linkage. +// * Throws `absl::bad_optional_access` instead of +// `std::bad_optional_access`. +// * `optional::swap()` and `absl::swap()` relies on +// `std::is_(nothrow_)swappable()`, which has been introduced in C++17. +// As a workaround, we assume `is_swappable()` is always `true` +// and `is_nothrow_swappable()` is the same as `std::is_trivial()`. +// * `make_optional()` cannot be declared `constexpr` due to the absence of +// guaranteed copy elision. +// * The move constructor's `noexcept` specification is stronger, i.e. if the +// default allocator is non-throwing (via setting +// `ABSL_ALLOCATOR_NOTHROW`), it evaluates to `noexcept(true)`, because +// we assume +// a) move constructors should only throw due to allocation failure and +// b) if T's move constructor allocates, it uses the same allocation +// function as the default allocator. +template +class optional; + +// nullopt_t +// +// Class type for `absl::nullopt` used to indicate an `absl::optional` type +// that does not contain a value. +struct nullopt_t { + struct init_t {}; + static init_t init; + + // It must not be default-constructible to avoid ambiguity for opt = {}. + // Note the non-const reference, which is to eliminate ambiguity for code + // like: + // + // struct S { int value; }; + // + // void Test() { + // optional opt; + // opt = {{}}; + // } + explicit constexpr nullopt_t(init_t& /*unused*/) {} +}; + +// nullopt +// +// A tag constant of type `absl::nullopt_t` used to indicate an empty +// `absl::optional` in certain functions, such as construction or assignment. +extern const nullopt_t nullopt; + +namespace optional_internal { + +struct empty_struct {}; +// This class stores the data in optional. +// It is specialized based on whether T is trivially destructible. +// This is the specialization for non trivially destructible type. +template ::value> +class optional_data_dtor_base { + struct dummy_type { + static_assert(sizeof(T) % sizeof(empty_struct) == 0, ""); + // Use an array to avoid GCC 6 placement-new warning. + empty_struct data[sizeof(T) / sizeof(empty_struct)]; + }; + + protected: + // Whether there is data or not. + bool engaged_; + // Data storage + union { + dummy_type dummy_; + T data_; + }; + + void destruct() noexcept { + if (engaged_) { + data_.~T(); + engaged_ = false; + } + } + + // dummy_ must be initialized for constexpr constructor. + constexpr optional_data_dtor_base() noexcept : engaged_(false), dummy_{{}} {} + + template + constexpr explicit optional_data_dtor_base(in_place_t, Args&&... args) + : engaged_(true), data_(absl::forward(args)...) {} + + ~optional_data_dtor_base() { destruct(); } +}; + +// Specialization for trivially destructible type. +template +class optional_data_dtor_base { + struct dummy_type { + static_assert(sizeof(T) % sizeof(empty_struct) == 0, ""); + // Use array to avoid GCC 6 placement-new warning. + empty_struct data[sizeof(T) / sizeof(empty_struct)]; + }; + + protected: + // Whether there is data or not. + bool engaged_; + // Data storage + union { + dummy_type dummy_; + T data_; + }; + void destruct() noexcept { engaged_ = false; } + + // dummy_ must be initialized for constexpr constructor. + constexpr optional_data_dtor_base() noexcept : engaged_(false), dummy_{{}} {} + + template + constexpr explicit optional_data_dtor_base(in_place_t, Args&&... args) + : engaged_(true), data_(absl::forward(args)...) {} +}; + +template +class optional_data_base : public optional_data_dtor_base { + protected: + using base = optional_data_dtor_base; +#if ABSL_OPTIONAL_USE_INHERITING_CONSTRUCTORS + using base::base; +#else + optional_data_base() = default; + + template + constexpr explicit optional_data_base(in_place_t t, Args&&... args) + : base(t, absl::forward(args)...) {} +#endif + + template + void construct(Args&&... args) { + // Use dummy_'s address to work around casting cv-qualified T* to void*. + ::new (static_cast(&this->dummy_)) T(std::forward(args)...); + this->engaged_ = true; + } + + template + void assign(U&& u) { + if (this->engaged_) { + this->data_ = std::forward(u); + } else { + construct(std::forward(u)); + } + } +}; + +// TODO(absl-team): Add another class using +// std::is_trivially_move_constructible trait when available to match +// http://cplusplus.github.io/LWG/lwg-defects.html#2900, for types that +// have trivial move but nontrivial copy. +// Also, we should be checking is_trivially_copyable here, which is not +// supported now, so we use is_trivially_* traits instead. +template ::value&& + absl::is_trivially_copy_assignable< + typename std::remove_cv::type>::value&& + std::is_trivially_destructible::value> +class optional_data; + +// Trivially copyable types +template +class optional_data : public optional_data_base { + protected: +#if ABSL_OPTIONAL_USE_INHERITING_CONSTRUCTORS + using optional_data_base::optional_data_base; +#else + optional_data() = default; + + template + constexpr explicit optional_data(in_place_t t, Args&&... args) + : optional_data_base(t, absl::forward(args)...) {} +#endif +}; + +template +class optional_data : public optional_data_base { + protected: +#if ABSL_OPTIONAL_USE_INHERITING_CONSTRUCTORS + using optional_data_base::optional_data_base; +#else + template + constexpr explicit optional_data(in_place_t t, Args&&... args) + : optional_data_base(t, absl::forward(args)...) {} +#endif + + optional_data() = default; + + optional_data(const optional_data& rhs) { + if (rhs.engaged_) { + this->construct(rhs.data_); + } + } + + optional_data(optional_data&& rhs) noexcept( + absl::default_allocator_is_nothrow::value || + std::is_nothrow_move_constructible::value) { + if (rhs.engaged_) { + this->construct(std::move(rhs.data_)); + } + } + + optional_data& operator=(const optional_data& rhs) { + if (rhs.engaged_) { + this->assign(rhs.data_); + } else { + this->destruct(); + } + return *this; + } + + optional_data& operator=(optional_data&& rhs) noexcept( + std::is_nothrow_move_assignable::value&& + std::is_nothrow_move_constructible::value) { + if (rhs.engaged_) { + this->assign(std::move(rhs.data_)); + } else { + this->destruct(); + } + return *this; + } +}; + +// Ordered by level of restriction, from low to high. +// Copyable implies movable. +enum class copy_traits { copyable = 0, movable = 1, non_movable = 2 }; + +// Base class for enabling/disabling copy/move constructor. +template +class optional_ctor_base; + +template <> +class optional_ctor_base { + public: + constexpr optional_ctor_base() = default; + optional_ctor_base(const optional_ctor_base&) = default; + optional_ctor_base(optional_ctor_base&&) = default; + optional_ctor_base& operator=(const optional_ctor_base&) = default; + optional_ctor_base& operator=(optional_ctor_base&&) = default; +}; + +template <> +class optional_ctor_base { + public: + constexpr optional_ctor_base() = default; + optional_ctor_base(const optional_ctor_base&) = delete; + optional_ctor_base(optional_ctor_base&&) = default; + optional_ctor_base& operator=(const optional_ctor_base&) = default; + optional_ctor_base& operator=(optional_ctor_base&&) = default; +}; + +template <> +class optional_ctor_base { + public: + constexpr optional_ctor_base() = default; + optional_ctor_base(const optional_ctor_base&) = delete; + optional_ctor_base(optional_ctor_base&&) = delete; + optional_ctor_base& operator=(const optional_ctor_base&) = default; + optional_ctor_base& operator=(optional_ctor_base&&) = default; +}; + +// Base class for enabling/disabling copy/move assignment. +template +class optional_assign_base; + +template <> +class optional_assign_base { + public: + constexpr optional_assign_base() = default; + optional_assign_base(const optional_assign_base&) = default; + optional_assign_base(optional_assign_base&&) = default; + optional_assign_base& operator=(const optional_assign_base&) = default; + optional_assign_base& operator=(optional_assign_base&&) = default; +}; + +template <> +class optional_assign_base { + public: + constexpr optional_assign_base() = default; + optional_assign_base(const optional_assign_base&) = default; + optional_assign_base(optional_assign_base&&) = default; + optional_assign_base& operator=(const optional_assign_base&) = delete; + optional_assign_base& operator=(optional_assign_base&&) = default; +}; + +template <> +class optional_assign_base { + public: + constexpr optional_assign_base() = default; + optional_assign_base(const optional_assign_base&) = default; + optional_assign_base(optional_assign_base&&) = default; + optional_assign_base& operator=(const optional_assign_base&) = delete; + optional_assign_base& operator=(optional_assign_base&&) = delete; +}; + +template +constexpr copy_traits get_ctor_copy_traits() { + return std::is_copy_constructible::value + ? copy_traits::copyable + : std::is_move_constructible::value ? copy_traits::movable + : copy_traits::non_movable; +} + +template +constexpr copy_traits get_assign_copy_traits() { + return std::is_copy_assignable::value && + std::is_copy_constructible::value + ? copy_traits::copyable + : std::is_move_assignable::value && + std::is_move_constructible::value + ? copy_traits::movable + : copy_traits::non_movable; +} + +// Whether T is constructible or convertible from optional. +template +struct is_constructible_convertible_from_optional + : std::integral_constant< + bool, std::is_constructible&>::value || + std::is_constructible&&>::value || + std::is_constructible&>::value || + std::is_constructible&&>::value || + std::is_convertible&, T>::value || + std::is_convertible&&, T>::value || + std::is_convertible&, T>::value || + std::is_convertible&&, T>::value> {}; + +// Whether T is constructible or convertible or assignable from optional. +template +struct is_constructible_convertible_assignable_from_optional + : std::integral_constant< + bool, is_constructible_convertible_from_optional::value || + std::is_assignable&>::value || + std::is_assignable&&>::value || + std::is_assignable&>::value || + std::is_assignable&&>::value> {}; + +// Helper function used by [optional.relops], [optional.comp_with_t], +// for checking whether an expression is convertible to bool. +bool convertible_to_bool(bool); + +// Base class for std::hash>: +// If std::hash> is enabled, it provides operator() to +// compute the hash; Otherwise, it is disabled. +// Reference N4659 23.14.15 [unord.hash]. +template +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 +struct optional_hash_base >()( + std::declval >()))> { + using argument_type = absl::optional; + using result_type = size_t; + size_t operator()(const absl::optional& opt) const { + if (opt) { + return std::hash >()(*opt); + } else { + return static_cast(0x297814aaad196e6dULL); + } + } +}; + +} // namespace optional_internal + +// ----------------------------------------------------------------------------- +// absl::optional class definition +// ----------------------------------------------------------------------------- + +template +class optional : private optional_internal::optional_data, + private optional_internal::optional_ctor_base< + optional_internal::get_ctor_copy_traits()>, + private optional_internal::optional_assign_base< + optional_internal::get_assign_copy_traits()> { + using data_base = optional_internal::optional_data; + + public: + typedef T value_type; + + // Constructors + + // Constructs an `optional` holding an empty value, NOT a default constructed + // `T`. + constexpr optional() noexcept {} + + // Constructs an `optional` initialized with `nullopt` to hold an empty value. + constexpr optional(nullopt_t) noexcept {} // NOLINT(runtime/explicit) + + // Copy constructor, standard semantics + optional(const optional& src) = default; + + // Move constructor, standard semantics + optional(optional&& src) = default; + + // Constructs a non-empty `optional` direct-initialized value of type `T` from + // the arguments `std::forward(args)...` within the `optional`. + // (The `in_place_t` is a tag used to indicate that the contained object + // should be constructed in-place.) + // + // TODO(absl-team): Add std::is_constructible SFINAE. + template + constexpr explicit optional(in_place_t, Args&&... args) + : data_base(in_place_t(), absl::forward(args)...) {} + + // Constructs a non-empty `optional` direct-initialized value of type `T` from + // the arguments of an initializer_list and `std::forward(args)...`. + // (The `in_place_t` is a tag used to indicate that the contained object + // should be constructed in-place.) + template &, Args&&...>::value>::type> + constexpr explicit optional(in_place_t, std::initializer_list il, + Args&&... args) + : data_base(in_place_t(), il, absl::forward(args)...) { + } + + // Value constructor (implicit) + template < + typename U = T, + typename std::enable_if< + absl::conjunction::type> >, + absl::negation, typename std::decay::type> >, + std::is_convertible, + std::is_constructible >::value, + bool>::type = false> + constexpr optional(U&& v) : data_base(in_place_t(), absl::forward(v)) {} + + // Value constructor (explicit) + template < + typename U = T, + typename std::enable_if< + absl::conjunction::type>>, + absl::negation, typename std::decay::type>>, + absl::negation>, + std::is_constructible>::value, + bool>::type = false> + explicit constexpr optional(U&& v) + : data_base(in_place_t(), absl::forward(v)) {} + + // Converting copy constructor (implicit) + template >, + std::is_constructible, + absl::negation< + optional_internal:: + is_constructible_convertible_from_optional >, + std::is_convertible >::value, + bool>::type = false> + optional(const optional& rhs) { + if (rhs) { + this->construct(*rhs); + } + } + + // Converting copy constructor (explicit) + template >, + std::is_constructible, + absl::negation< + optional_internal:: + is_constructible_convertible_from_optional>, + absl::negation>>::value, + bool>::type = false> + explicit optional(const optional& rhs) { + if (rhs) { + this->construct(*rhs); + } + } + + // Converting move constructor (implicit) + template >, + std::is_constructible, + absl::negation< + optional_internal:: + is_constructible_convertible_from_optional >, + std::is_convertible >::value, + bool>::type = false> + optional(optional&& rhs) { + if (rhs) { + this->construct(std::move(*rhs)); + } + } + + // Converting move constructor (explicit) + template < + typename U, + typename std::enable_if< + absl::conjunction< + absl::negation>, std::is_constructible, + absl::negation< + optional_internal::is_constructible_convertible_from_optional< + T, U>>, + absl::negation>>::value, + bool>::type = false> + explicit optional(optional&& rhs) { + if (rhs) { + this->construct(std::move(*rhs)); + } + } + + // Destructor. Trivial if `T` is trivially destructible. + ~optional() = default; + + // Assignment Operators + + // Assignment from `nullopt` + // + // Example: + // + // struct S { int value; }; + // optional opt = absl::nullopt; // Could also use opt = { }; + optional& operator=(nullopt_t) noexcept { + this->destruct(); + return *this; + } + + // Copy assignment operator, standard semantics + optional& operator=(const optional& src) = default; + + // Move assignment operator, standard semantics + optional& operator=(optional&& src) = default; + + // Value assignment operators + template < + typename U = T, + typename = typename std::enable_if, typename std::decay::type>>, + absl::negation< + absl::conjunction, + std::is_same::type>>>, + std::is_constructible, std::is_assignable>::value>::type> + optional& operator=(U&& v) { + this->assign(std::forward(v)); + return *this; + } + + template < + typename U, + typename = typename std::enable_if>, + std::is_constructible, std::is_assignable, + absl::negation< + optional_internal:: + is_constructible_convertible_assignable_from_optional< + T, U>>>::value>::type> + optional& operator=(const optional& rhs) { + if (rhs) { + this->assign(*rhs); + } else { + this->destruct(); + } + return *this; + } + + template >, std::is_constructible, + std::is_assignable, + absl::negation< + optional_internal:: + is_constructible_convertible_assignable_from_optional< + T, U>>>::value>::type> + optional& operator=(optional&& rhs) { + if (rhs) { + this->assign(std::move(*rhs)); + } else { + this->destruct(); + } + return *this; + } + + // Modifiers + + // optional::reset() + // + // Destroys the inner `T` value of an `absl::optional` if one is present. + void reset() noexcept { this->destruct(); } + + // optional::emplace() + // + // (Re)constructs the underlying `T` in-place with the given forwarded + // arguments. + // + // Example: + // + // optional opt; + // opt.emplace(arg1,arg2,arg3); // Constructs Foo(arg1,arg2,arg3) + // + // If the optional is non-empty, and the `args` refer to subobjects of the + // current object, then behaviour is undefined, because the current object + // will be destructed before the new object is constructed with `args`. + template ::value>::type> + T& emplace(Args&&... args) { + this->destruct(); + this->construct(std::forward(args)...); + return reference(); + } + + // Emplace reconstruction overload for an initializer list and the given + // forwarded arguments. + // + // Example: + // + // struct Foo { + // Foo(std::initializer_list); + // }; + // + // optional opt; + // opt.emplace({1,2,3}); // Constructs Foo({1,2,3}) + template &, Args&&...>::value>::type> + T& emplace(std::initializer_list il, Args&&... args) { + this->destruct(); + this->construct(il, std::forward(args)...); + return reference(); + } + + // Swaps + + // Swap, standard semantics + void swap(optional& rhs) noexcept( + std::is_nothrow_move_constructible::value&& + std::is_trivial::value) { + if (*this) { + if (rhs) { + using std::swap; + swap(**this, *rhs); + } else { + rhs.construct(std::move(**this)); + this->destruct(); + } + } else { + if (rhs) { + this->construct(std::move(*rhs)); + rhs.destruct(); + } else { + // No effect (swap(disengaged, disengaged)). + } + } + } + + // Observers + + // optional::operator->() + // + // Accesses the underlying `T` value's member `m` of an `optional`. If the + // `optional` is empty, behavior is undefined. + constexpr const T* operator->() const { return this->pointer(); } + T* operator->() { + assert(this->engaged_); + return this->pointer(); + } + + // optional::operator*() + // + // Accesses the underlying `T` value of an `optional`. If the `optional` is + // empty, behavior is undefined. + constexpr const T& operator*() const & { return reference(); } + T& operator*() & { + assert(this->engaged_); + return reference(); + } + constexpr const T&& operator*() const && { + return absl::move(reference()); + } + T&& operator*() && { + assert(this->engaged_); + return std::move(reference()); + } + + // optional::operator bool() + // + // Returns false if and only if the `optional` is empty. + // + // if (opt) { + // // do something with opt.value(); + // } else { + // // opt is empty. + // } + // + constexpr explicit operator bool() const noexcept { return this->engaged_; } + + // optional::has_value() + // + // Determines whether the `optional` contains a value. Returns `false` if and + // only if `*this` is empty. + constexpr bool has_value() const noexcept { return this->engaged_; } + + // optional::value() + // + // Returns a reference to an `optional`s underlying value. The constness + // and lvalue/rvalue-ness of the `optional` is preserved to the view of + // the `T` sub-object. Throws `absl::bad_optional_access` when the `optional` + // is empty. + constexpr const T& value() const & { + return static_cast(*this) + ? reference() + : (optional_internal::throw_bad_optional_access(), reference()); + } + T& value() & { + return static_cast(*this) + ? reference() + : (optional_internal::throw_bad_optional_access(), reference()); + } + T&& value() && { // NOLINT(build/c++11) + return std::move( + static_cast(*this) + ? reference() + : (optional_internal::throw_bad_optional_access(), reference())); + } + constexpr const T&& value() const && { // NOLINT(build/c++11) + return absl::move( + static_cast(*this) + ? reference() + : (optional_internal::throw_bad_optional_access(), reference())); + } + + // optional::value_or() + // + // Returns either the value of `T` or a passed default `v` if the `optional` + // is empty. + template + constexpr T value_or(U&& v) const& { + static_assert(std::is_copy_constructible::value, + "optional::value_or: T must by copy constructible"); + static_assert(std::is_convertible::value, + "optional::value_or: U must be convertible to T"); + return static_cast(*this) + ? **this + : static_cast(absl::forward(v)); + } + template + T value_or(U&& v) && { // NOLINT(build/c++11) + static_assert(std::is_move_constructible::value, + "optional::value_or: T must by copy constructible"); + static_assert(std::is_convertible::value, + "optional::value_or: U must be convertible to T"); + return static_cast(*this) ? std::move(**this) + : static_cast(std::forward(v)); + } + + private: + // Private accessors for internal storage viewed as pointer to T. + constexpr const T* pointer() const { return &this->data_; } + T* pointer() { return &this->data_; } + + // Private accessors for internal storage viewed as reference to T. + constexpr const T& reference() const { return *this->pointer(); } + T& reference() { return *(this->pointer()); } + + // T constraint checks. You can't have an optional of nullopt_t, in_place_t + // or a reference. + static_assert( + !std::is_same::type>::value, + "optional is not allowed."); + static_assert( + !std::is_same::type>::value, + "optional is not allowed."); + static_assert(!std::is_reference::value, + "optional is not allowed."); +}; + +// Non-member functions + +// swap() +// +// Performs a swap between two `absl::optional` objects, using standard +// semantics. +// +// NOTE: we assume `is_swappable()` is always `true`. A compile error will +// result if this is not the case. +template ::value, + bool>::type = false> +void swap(optional& a, optional& b) noexcept(noexcept(a.swap(b))) { + a.swap(b); +} + +// make_optional() +// +// Creates a non-empty `optional` where the type of `T` is deduced. An +// `absl::optional` can also be explicitly instantiated with +// `make_optional(v)`. +// +// Note: `make_optional()` constructions may be declared `constexpr` for +// trivially copyable types `T`. Non-trivial types require copy elision +// support in C++17 for `make_optional` to support `constexpr` on such +// non-trivial types. +// +// Example: +// +// constexpr absl::optional opt = absl::make_optional(1); +// static_assert(opt.value() == 1, ""); +template +constexpr optional::type> make_optional(T&& v) { + return optional::type>(absl::forward(v)); +} + +template +constexpr optional make_optional(Args&&... args) { + return optional(in_place_t(), absl::forward(args)...); +} + +template +constexpr optional make_optional(std::initializer_list il, + Args&&... args) { + return optional(in_place_t(), il, + absl::forward(args)...); +} + +// Relational operators [optional.relops] + +// Empty optionals are considered equal to each other and less than non-empty +// optionals. Supports relations between optional and optional, between +// optional and U, and between optional and nullopt. +// +// Note: We're careful to support T having non-bool relationals. + +// Requires: The expression, e.g. "*x == *y" shall be well-formed and its result +// shall be convertible to bool. +// The C++17 (N4606) "Returns:" statements are translated into +// code in an obvious way here, and the original text retained as function docs. +// Returns: If bool(x) != bool(y), false; otherwise if bool(x) == false, true; +// otherwise *x == *y. +template +constexpr auto operator==(const optional& x, const optional& y) + -> decltype(optional_internal::convertible_to_bool(*x == *y)) { + return static_cast(x) != static_cast(y) + ? false + : static_cast(x) == false ? true : *x == *y; +} + +// Returns: If bool(x) != bool(y), true; otherwise, if bool(x) == false, false; +// otherwise *x != *y. +template +constexpr auto operator!=(const optional& x, const optional& y) + -> decltype(optional_internal::convertible_to_bool(*x != *y)) { + return static_cast(x) != static_cast(y) + ? true + : static_cast(x) == false ? false : *x != *y; +} +// Returns: If !y, false; otherwise, if !x, true; otherwise *x < *y. +template +constexpr auto operator<(const optional& x, const optional& y) + -> decltype(optional_internal::convertible_to_bool(*x < *y)) { + return !y ? false : !x ? true : *x < *y; +} +// Returns: If !x, false; otherwise, if !y, true; otherwise *x > *y. +template +constexpr auto operator>(const optional& x, const optional& y) + -> decltype(optional_internal::convertible_to_bool(*x > *y)) { + return !x ? false : !y ? true : *x > *y; +} +// Returns: If !x, true; otherwise, if !y, false; otherwise *x <= *y. +template +constexpr auto operator<=(const optional& x, const optional& y) + -> decltype(optional_internal::convertible_to_bool(*x <= *y)) { + return !x ? true : !y ? false : *x <= *y; +} +// Returns: If !y, true; otherwise, if !x, false; otherwise *x >= *y. +template +constexpr auto operator>=(const optional& x, const optional& y) + -> decltype(optional_internal::convertible_to_bool(*x >= *y)) { + return !y ? true : !x ? false : *x >= *y; +} + +// Comparison with nullopt [optional.nullops] +// The C++17 (N4606) "Returns:" statements are used directly here. +template +constexpr bool operator==(const optional& x, nullopt_t) noexcept { + return !x; +} +template +constexpr bool operator==(nullopt_t, const optional& x) noexcept { + return !x; +} +template +constexpr bool operator!=(const optional& x, nullopt_t) noexcept { + return static_cast(x); +} +template +constexpr bool operator!=(nullopt_t, const optional& x) noexcept { + return static_cast(x); +} +template +constexpr bool operator<(const optional&, nullopt_t) noexcept { + return false; +} +template +constexpr bool operator<(nullopt_t, const optional& x) noexcept { + return static_cast(x); +} +template +constexpr bool operator<=(const optional& x, nullopt_t) noexcept { + return !x; +} +template +constexpr bool operator<=(nullopt_t, const optional&) noexcept { + return true; +} +template +constexpr bool operator>(const optional& x, nullopt_t) noexcept { + return static_cast(x); +} +template +constexpr bool operator>(nullopt_t, const optional&) noexcept { + return false; +} +template +constexpr bool operator>=(const optional&, nullopt_t) noexcept { + return true; +} +template +constexpr bool operator>=(nullopt_t, const optional& x) noexcept { + return !x; +} + +// Comparison with T [optional.comp_with_t] + +// Requires: The expression, e.g. "*x == v" shall be well-formed and its result +// shall be convertible to bool. +// The C++17 (N4606) "Equivalent to:" statements are used directly here. +template +constexpr auto operator==(const optional& x, const U& v) + -> decltype(optional_internal::convertible_to_bool(*x == v)) { + return static_cast(x) ? *x == v : false; +} +template +constexpr auto operator==(const U& v, const optional& x) + -> decltype(optional_internal::convertible_to_bool(v == *x)) { + return static_cast(x) ? v == *x : false; +} +template +constexpr auto operator!=(const optional& x, const U& v) + -> decltype(optional_internal::convertible_to_bool(*x != v)) { + return static_cast(x) ? *x != v : true; +} +template +constexpr auto operator!=(const U& v, const optional& x) + -> decltype(optional_internal::convertible_to_bool(v != *x)) { + return static_cast(x) ? v != *x : true; +} +template +constexpr auto operator<(const optional& x, const U& v) + -> decltype(optional_internal::convertible_to_bool(*x < v)) { + return static_cast(x) ? *x < v : true; +} +template +constexpr auto operator<(const U& v, const optional& x) + -> decltype(optional_internal::convertible_to_bool(v < *x)) { + return static_cast(x) ? v < *x : false; +} +template +constexpr auto operator<=(const optional& x, const U& v) + -> decltype(optional_internal::convertible_to_bool(*x <= v)) { + return static_cast(x) ? *x <= v : true; +} +template +constexpr auto operator<=(const U& v, const optional& x) + -> decltype(optional_internal::convertible_to_bool(v <= *x)) { + return static_cast(x) ? v <= *x : false; +} +template +constexpr auto operator>(const optional& x, const U& v) + -> decltype(optional_internal::convertible_to_bool(*x > v)) { + return static_cast(x) ? *x > v : false; +} +template +constexpr auto operator>(const U& v, const optional& x) + -> decltype(optional_internal::convertible_to_bool(v > *x)) { + return static_cast(x) ? v > *x : true; +} +template +constexpr auto operator>=(const optional& x, const U& v) + -> decltype(optional_internal::convertible_to_bool(*x >= v)) { + return static_cast(x) ? *x >= v : false; +} +template +constexpr auto operator>=(const U& v, const optional& x) + -> decltype(optional_internal::convertible_to_bool(v >= *x)) { + return static_cast(x) ? v >= *x : true; +} + +} // namespace absl + +namespace std { + +// std::hash specialization for absl::optional. +template +struct hash > + : absl::optional_internal::optional_hash_base {}; + +} // namespace std + +#undef ABSL_OPTIONAL_USE_INHERITING_CONSTRUCTORS +#undef ABSL_MSVC_CONSTEXPR_BUG_IN_UNION_LIKE_CLASS + +#endif // ABSL_HAVE_STD_OPTIONAL + +#endif // ABSL_TYPES_OPTIONAL_H_ diff --git a/Firestore/third_party/abseil-cpp/absl/utility/utility.h b/Firestore/third_party/abseil-cpp/absl/utility/utility.h new file mode 100644 index 0000000..1943c4a --- /dev/null +++ b/Firestore/third_party/abseil-cpp/absl/utility/utility.h @@ -0,0 +1,264 @@ +// 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. +// +// This header file contains C++11 versions of standard 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. +// +// The following abstractions are defined: +// +// * integer_sequence == std::integer_sequence +// * index_sequence == std::index_sequence +// * make_integer_sequence == std::make_integer_sequence +// * make_index_sequence == std::make_index_sequence +// * index_sequence_for == std::index_sequence_for +// * apply == std::apply +// +// 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: +// +// http://en.cppreference.com/w/cpp/utility/integer_sequence +// http://en.cppreference.com/w/cpp/utility/apply +// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3658.html +// + +#ifndef ABSL_UTILITY_UTILITY_H_ +#define ABSL_UTILITY_UTILITY_H_ + +#include +#include +#include +#include + +#include "absl/base/config.h" +#include "absl/base/internal/inline_variable.h" +#include "absl/base/internal/invoke.h" +#include "absl/meta/type_traits.h" + +namespace absl { + +// integer_sequence +// +// Class template representing a compile-time integer sequence. An instantiation +// of `integer_sequence` has a sequence of integers encoded in its +// 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`. +// +// Example: +// +// template< class T, T... Ints > +// void user_function(integer_sequence); +// +// 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()); +// } +template +struct integer_sequence { + using value_type = T; + static constexpr size_t size() noexcept { return sizeof...(Ints); } +}; + +// index_sequence +// +// 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 +using index_sequence = integer_sequence; + +namespace utility_internal { + +template +struct Extend; + +// Note that SeqSize == sizeof...(Ints). It's passed explicitly for efficiency. +template +struct Extend, SeqSize, 0> { + using type = integer_sequence; +}; + +template +struct Extend, SeqSize, 1> { + using type = integer_sequence; +}; + +// Recursion helper for 'make_integer_sequence'. +// 'Gen::type' is an alias for 'integer_sequence'. +template +struct Gen { + using type = + typename Extend::type, N / 2, N % 2>::type; +}; + +template +struct Gen { + using type = integer_sequence; +}; + +} // namespace utility_internal + +// Compile-time sequences of integers + +// make_integer_sequence +// +// This template alias is equivalent to +// `integer_sequence`, and is designed to be a drop-in +// replacement for C++14's `std::make_integer_sequence`. +template +using make_integer_sequence = typename utility_internal::Gen::type; + +// make_index_sequence +// +// 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 +using make_index_sequence = make_integer_sequence; + +// index_sequence_for +// +// 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 +using index_sequence_for = make_index_sequence; + +// Tag types + +#ifdef ABSL_HAVE_STD_OPTIONAL + +using std::in_place_t; +using std::in_place; + +#else // ABSL_HAVE_STD_OPTIONAL + +// in_place_t +// +// 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 {}; + +ABSL_INTERNAL_INLINE_CONSTEXPR(in_place_t, in_place, {}); + +#endif // ABSL_HAVE_STD_OPTIONAL + +#ifdef ABSL_HAVE_STD_ANY +using std::in_place_type_t; +#else + +// 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 +struct in_place_type_t {}; +#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 +struct in_place_index_t {}; + +// 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 +constexpr absl::remove_reference_t&& move(T&& t) noexcept { + return static_cast&&>(t); +} + +// forward() +// +// A constexpr version of `std::forward()`, designed to be a drop-in replacement +// for C++14's `std::forward()`. +template +constexpr T&& forward( + absl::remove_reference_t& t) noexcept { // NOLINT(runtime/references) + return static_cast(t); +} + +namespace utility_internal { +// Helper method for expanding tuple into a called method. +template +auto apply_helper(Functor&& functor, Tuple&& t, index_sequence) + -> decltype(absl::base_internal::Invoke( + absl::forward(functor), + std::get(absl::forward(t))...)) { + return absl::base_internal::Invoke( + absl::forward(functor), + std::get(absl::forward(t))...); +} + +} // namespace utility_internal + +// apply +// +// Invokes a Callable using elements of a tuple as its arguments. +// Each element of the tuple corresponds to an argument of the call (in order). +// Both the Callable argument and the tuple argument are perfect-forwarded. +// For member-function Callables, the first tuple element acts as the `this` +// pointer. `absl::apply` is designed to be a drop-in replacement for C++17's +// `std::apply`. Unlike C++17's `std::apply`, this is not currently `constexpr`. +// +// Example: +// +// class Foo{void Bar(int);}; +// void user_function(int, std::string); +// void user_function(std::unique_ptr); +// +// int main() +// { +// std::tuple tuple1(42, "bar"); +// // Invokes the user function overload on int, std::string. +// absl::apply(&user_function, tuple1); +// +// auto foo = absl::make_unique(); +// std::tuple tuple2(foo.get(), 42); +// // Invokes the method Bar on foo with one argument 42. +// absl::apply(&Foo::Bar, foo.get(), 42); +// +// std::tuple> tuple3(absl::make_unique()); +// // Invokes the user function that takes ownership of the unique +// // pointer. +// absl::apply(&user_function, std::move(tuple)); +// } +template +auto apply(Functor&& functor, Tuple&& t) + -> decltype(utility_internal::apply_helper( + absl::forward(functor), absl::forward(t), + absl::make_index_sequence::type>::value>{})) { + return utility_internal::apply_helper( + absl::forward(functor), absl::forward(t), + absl::make_index_sequence::type>::value>{}); +} +} // namespace absl + +#endif // ABSL_UTILITY_UTILITY_H_ -- cgit v1.2.3 From dfb5c04cf87fdff3c7fc16f9de3a2e8e1f4df265 Mon Sep 17 00:00:00 2001 From: Marek Gilbert Date: Sun, 15 Apr 2018 16:10:47 -0700 Subject: Update abseil-cpp to a new upstream Actually update to bf7fc9986e20f664958fc227547fd8d2fdcf863e Change #754 didn't completely do this. This makes the rest of the sources match optional, which was imported at this change in #1083. Also add: absl/types/optional_test.cc absl/types/CMakeLists.txt absl/utility/CMakeLists.txt --- Firestore/third_party/abseil-cpp/CMakeLists.txt | 1 + .../abseil-cpp/absl/base/CMakeLists.txt | 1 + .../third_party/abseil-cpp/absl/base/attributes.h | 21 +- .../third_party/abseil-cpp/absl/base/config.h | 37 +- .../abseil-cpp/absl/base/internal/raw_logging.cc | 21 +- .../abseil-cpp/absl/base/internal/raw_logging.h | 7 + .../abseil-cpp/absl/base/log_severity.h | 8 +- .../third_party/abseil-cpp/absl/base/macros.h | 2 +- .../abseil-cpp/absl/base/policy_checks.h | 30 +- .../third_party/abseil-cpp/absl/meta/type_traits.h | 4 + .../third_party/abseil-cpp/absl/numeric/int128.cc | 73 +- .../third_party/abseil-cpp/absl/numeric/int128.h | 262 ++-- .../absl/numeric/int128_have_intrinsic.inc | 19 +- .../absl/numeric/int128_no_intrinsic.inc | 19 +- .../abseil-cpp/absl/numeric/int128_test.cc | 6 +- .../abseil-cpp/absl/strings/escaping_test.cc | 1 + .../absl/strings/internal/stl_type_traits.h | 121 +- .../abseil-cpp/absl/strings/internal/utf8.h | 4 - .../third_party/abseil-cpp/absl/strings/str_cat.cc | 31 + .../third_party/abseil-cpp/absl/strings/str_cat.h | 62 +- .../abseil-cpp/absl/strings/str_cat_test.cc | 97 +- .../abseil-cpp/absl/strings/str_split.h | 4 +- .../abseil-cpp/absl/strings/str_split_test.cc | 41 +- .../abseil-cpp/absl/strings/strip_test.cc | 20 + .../abseil-cpp/absl/strings/substitute_test.cc | 10 +- .../abseil-cpp/absl/types/CMakeLists.txt | 188 +++ .../abseil-cpp/absl/types/optional_test.cc | 1598 ++++++++++++++++++++ .../abseil-cpp/absl/utility/CMakeLists.txt | 45 + 28 files changed, 2451 insertions(+), 282 deletions(-) create mode 100644 Firestore/third_party/abseil-cpp/absl/types/CMakeLists.txt create mode 100644 Firestore/third_party/abseil-cpp/absl/types/optional_test.cc create mode 100644 Firestore/third_party/abseil-cpp/absl/utility/CMakeLists.txt (limited to 'Firestore/third_party') diff --git a/Firestore/third_party/abseil-cpp/CMakeLists.txt b/Firestore/third_party/abseil-cpp/CMakeLists.txt index 6d3789e..6e715af 100644 --- a/Firestore/third_party/abseil-cpp/CMakeLists.txt +++ b/Firestore/third_party/abseil-cpp/CMakeLists.txt @@ -70,6 +70,7 @@ if(NOT ABSL_CCTZ_TARGET) endif() # commented: used only for standalone test +# Don't remove these or else CMake CI will break #add_subdirectory(cctz) #add_subdirectory(googletest) check_target(${ABSL_CCTZ_TARGET}) diff --git a/Firestore/third_party/abseil-cpp/absl/base/CMakeLists.txt b/Firestore/third_party/abseil-cpp/absl/base/CMakeLists.txt index 4b7b53a..ced81b6 100644 --- a/Firestore/third_party/abseil-cpp/absl/base/CMakeLists.txt +++ b/Firestore/third_party/abseil-cpp/absl/base/CMakeLists.txt @@ -32,6 +32,7 @@ list(APPEND BASE_PUBLIC_HEADERS list(APPEND BASE_INTERNAL_HEADERS "internal/atomic_hook.h" "internal/cycleclock.h" + "internal/direct_mmap.h" "internal/endian.h" "internal/exception_testing.h" "internal/exception_safety_testing.h" diff --git a/Firestore/third_party/abseil-cpp/absl/base/attributes.h b/Firestore/third_party/abseil-cpp/absl/base/attributes.h index 4e1fc8b..a4ec7e7 100644 --- a/Firestore/third_party/abseil-cpp/absl/base/attributes.h +++ b/Firestore/third_party/abseil-cpp/absl/base/attributes.h @@ -527,17 +527,34 @@ #define ABSL_ATTRIBUTE_PACKED #endif +// ABSL_ATTRIBUTE_FUNC_ALIGN +// +// Tells the compiler to align the function start at least to certain +// alignment boundary +#if ABSL_HAVE_ATTRIBUTE(aligned) || (defined(__GNUC__) && !defined(__clang__)) +#define ABSL_ATTRIBUTE_FUNC_ALIGN(bytes) __attribute__((aligned(bytes))) +#else +#define ABSL_ATTRIBUTE_FUNC_ALIGN(bytes) +#endif + // ABSL_CONST_INIT // // A variable declaration annotated with the `ABSL_CONST_INIT` attribute will // not compile (on supported platforms) unless the variable has a constant // initializer. This is useful for variables with static and thread storage // duration, because it guarantees that they will not suffer from the so-called -// "static init order fiasco". +// "static init order fiasco". Prefer to put this attribute on the most visible +// declaration of the variable, if there's more than one, because code that +// accesses the variable can then use the attribute for optimization. // // Example: // -// ABSL_CONST_INIT static MyType my_var = MakeMyType(...); +// class MyClass { +// public: +// ABSL_CONST_INIT static MyType my_var; +// }; +// +// MyType MyClass::my_var = MakeMyType(...); // // Note that this attribute is redundant if the variable is declared constexpr. #if ABSL_HAVE_CPP_ATTRIBUTE(clang::require_constant_initialization) diff --git a/Firestore/third_party/abseil-cpp/absl/base/config.h b/Firestore/third_party/abseil-cpp/absl/base/config.h index 6703d0e..500bc8c 100644 --- a/Firestore/third_party/abseil-cpp/absl/base/config.h +++ b/Firestore/third_party/abseil-cpp/absl/base/config.h @@ -138,12 +138,16 @@ // supported. #ifdef ABSL_HAVE_THREAD_LOCAL #error ABSL_HAVE_THREAD_LOCAL cannot be directly set -#elif (!defined(__apple_build_version__) || \ - (__apple_build_version__ >= 8000042)) && \ - !(defined(__APPLE__) && TARGET_OS_IPHONE && \ - __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0) +#elif defined(__APPLE__) // Notes: Xcode's clang did not support `thread_local` until version -// 8, and even then not for all iOS < 9.0. +// 8, and even then not for all iOS < 9.0. Also, Xcode 9.3 started disallowing +// `thread_local` for 32-bit iOS simulator targeting iOS 9.x. +// `__has_feature` is only supported by Clang so it has be inside +// `defined(__APPLE__)` check. +#if __has_feature(cxx_thread_local) +#define ABSL_HAVE_THREAD_LOCAL 1 +#endif +#else // !defined(__APPLE__) #define ABSL_HAVE_THREAD_LOCAL 1 #endif @@ -176,16 +180,22 @@ // Checks whether the __int128 compiler extension for a 128-bit integral type is // supported. // -// Notes: __SIZEOF_INT128__ is defined by Clang and GCC when __int128 is -// supported, except on ppc64 and aarch64 where __int128 exists but has exhibits -// a sporadic compiler crashing bug. Nvidia's nvcc also defines __GNUC__ and -// __SIZEOF_INT128__ but not all versions actually support __int128. +// Note: __SIZEOF_INT128__ is defined by Clang and GCC when __int128 is +// supported, but we avoid using it in certain cases: +// * On Clang: +// * Building using Clang for Windows, where the Clang runtime library has +// 128-bit support only on LP64 architectures, but Windows is LLP64. +// * Building for aarch64, where __int128 exists but has exhibits a sporadic +// compiler crashing bug. +// * On Nvidia's nvcc: +// * nvcc also defines __GNUC__ and __SIZEOF_INT128__, but not all versions +// actually support __int128. #ifdef ABSL_HAVE_INTRINSIC_INT128 #error ABSL_HAVE_INTRINSIC_INT128 cannot be directly set #elif defined(__SIZEOF_INT128__) -#if (defined(__clang__) && !defined(__aarch64__)) || \ - (defined(__CUDACC__) && __CUDACC_VER_MAJOR__ >= 9) || \ - (!defined(__clang__) && !defined(__CUDACC__) && defined(__GNUC__)) +#if (defined(__clang__) && !defined(_WIN32) && !defined(__aarch64__)) || \ + (defined(__CUDACC__) && __CUDACC_VER_MAJOR__ >= 9) || \ + (defined(__GNUC__) && !defined(__clang__) && !defined(__CUDACC__)) #define ABSL_HAVE_INTRINSIC_INT128 1 #elif defined(__CUDACC__) // __CUDACC_VER__ is a full version number before CUDA 9, and is defined to a @@ -244,6 +254,7 @@ // Windows _WIN32 // NaCL __native_client__ // AsmJS __asmjs__ +// WebAssembly __wasm__ // Fuchsia __Fuchsia__ // // Note that since Android defines both __ANDROID__ and __linux__, one @@ -257,7 +268,7 @@ #error ABSL_HAVE_MMAP cannot be directly set #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \ defined(__ros__) || defined(__native_client__) || defined(__asmjs__) || \ - defined(__Fuchsia__) + defined(__wasm__) || defined(__Fuchsia__) #define ABSL_HAVE_MMAP 1 #endif diff --git a/Firestore/third_party/abseil-cpp/absl/base/internal/raw_logging.cc b/Firestore/third_party/abseil-cpp/absl/base/internal/raw_logging.cc index 86e34d4..1ce1388 100644 --- a/Firestore/third_party/abseil-cpp/absl/base/internal/raw_logging.cc +++ b/Firestore/third_party/abseil-cpp/absl/base/internal/raw_logging.cc @@ -20,6 +20,7 @@ #include #include +#include "absl/base/attributes.h" #include "absl/base/config.h" #include "absl/base/internal/atomic_hook.h" #include "absl/base/log_severity.h" @@ -35,7 +36,7 @@ // This preprocessor token is also defined in raw_io.cc. If you need to copy // this, consider moving both to config.h instead. #if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \ - defined(__Fuchsia__) + defined(__Fuchsia__) || defined(__native_client__) #include @@ -81,6 +82,8 @@ static const char kTruncated[] = " ... (message truncated)\n"; // consumed bytes, and return whether the message fit without truncation. If // truncation occurred, if possible leave room in the buffer for the message // kTruncated[]. +inline static bool VADoRawLog(char** buf, int* size, const char* format, + va_list ap) ABSL_PRINTF_ATTRIBUTE(3, 0); inline static bool VADoRawLog(char** buf, int* size, const char* format, va_list ap) { int n = vsnprintf(*buf, *size, format, ap); @@ -101,12 +104,6 @@ inline static bool VADoRawLog(char** buf, int* size, static constexpr int kLogBufSize = 3000; -namespace absl { -namespace raw_logging_internal { -void SafeWriteToStderr(const char *s, size_t len); -} // namespace raw_logging_internal -} // namespace absl - namespace { // CAVEAT: vsnprintf called from *DoRawLog below has some (exotic) code paths @@ -128,6 +125,8 @@ bool DoRawLog(char** buf, int* size, const char* format, ...) { return true; } +void RawLogVA(absl::LogSeverity severity, const char* file, int line, + const char* format, va_list ap) ABSL_PRINTF_ATTRIBUTE(4, 0); void RawLogVA(absl::LogSeverity severity, const char* file, int line, const char* format, va_list ap) { char buffer[kLogBufSize]; @@ -183,12 +182,6 @@ void RawLogVA(absl::LogSeverity severity, const char* file, int line, namespace absl { namespace raw_logging_internal { - -// Writes the provided buffer directly to stderr, in a safe, low-level manner. -// -// In POSIX this means calling write(), which is async-signal safe and does -// not malloc. If the platform supports the SYS_write syscall, we invoke that -// directly to side-step any libc interception. void SafeWriteToStderr(const char *s, size_t len) { #if defined(ABSL_HAVE_SYSCALL_WRITE) syscall(SYS_write, STDERR_FILENO, s, len); @@ -203,6 +196,8 @@ void SafeWriteToStderr(const char *s, size_t len) { #endif } +void RawLog(absl::LogSeverity severity, const char* file, int line, + const char* format, ...) ABSL_PRINTF_ATTRIBUTE(4, 5); void RawLog(absl::LogSeverity severity, const char* file, int line, const char* format, ...) { va_list ap; diff --git a/Firestore/third_party/abseil-cpp/absl/base/internal/raw_logging.h b/Firestore/third_party/abseil-cpp/absl/base/internal/raw_logging.h index 1b2a44b..a2b7207 100644 --- a/Firestore/third_party/abseil-cpp/absl/base/internal/raw_logging.h +++ b/Firestore/third_party/abseil-cpp/absl/base/internal/raw_logging.h @@ -74,6 +74,13 @@ namespace raw_logging_internal { void RawLog(absl::LogSeverity severity, const char* file, int line, const char* format, ...) ABSL_PRINTF_ATTRIBUTE(4, 5); +// Writes the provided buffer directly to stderr, in a safe, low-level manner. +// +// In POSIX this means calling write(), which is async-signal safe and does +// not malloc. If the platform supports the SYS_write syscall, we invoke that +// directly to side-step any libc interception. +void SafeWriteToStderr(const char *s, size_t len); + // compile-time function to get the "base" filename, that is, the part of // a filename after the last "/" or "\" path separator. The search starts at // the end of the std::string; the second parameter is the length of the std::string. diff --git a/Firestore/third_party/abseil-cpp/absl/base/log_severity.h b/Firestore/third_party/abseil-cpp/absl/base/log_severity.h index e146bcb..e2931c3 100644 --- a/Firestore/third_party/abseil-cpp/absl/base/log_severity.h +++ b/Firestore/third_party/abseil-cpp/absl/base/log_severity.h @@ -22,6 +22,9 @@ namespace absl { +// Four severity levels are defined. Logging APIs should terminate the program +// when a message is logged at severity `kFatal`; the other levels have no +// special semantics. enum class LogSeverity : int { kInfo = 0, kWarning = 1, @@ -36,6 +39,8 @@ constexpr std::array LogSeverities() { absl::LogSeverity::kError, absl::LogSeverity::kFatal}}; } +// Returns the all-caps std::string representation (e.g. "INFO") of the specified +// severity level if it is one of the normal levels and "UNKNOWN" otherwise. constexpr const char* LogSeverityName(absl::LogSeverity s) { return s == absl::LogSeverity::kInfo ? "INFO" @@ -46,7 +51,8 @@ constexpr const char* LogSeverityName(absl::LogSeverity s) { : s == absl::LogSeverity::kFatal ? "FATAL" : "UNKNOWN"; } -// Note that out-of-range severities normalize to kInfo or kError, never kFatal. +// Values less than `kInfo` normalize to `kInfo`; values greater than `kFatal` +// normalize to `kError` (**NOT** `kFatal`). constexpr absl::LogSeverity NormalizeLogSeverity(absl::LogSeverity s) { return s < absl::LogSeverity::kInfo ? absl::LogSeverity::kInfo diff --git a/Firestore/third_party/abseil-cpp/absl/base/macros.h b/Firestore/third_party/abseil-cpp/absl/base/macros.h index 5ae0f05..114a7be 100644 --- a/Firestore/third_party/abseil-cpp/absl/base/macros.h +++ b/Firestore/third_party/abseil-cpp/absl/base/macros.h @@ -46,7 +46,7 @@ namespace absl { namespace macros_internal { template -char (&ArraySizeHelper(T (&array)[N]))[N]; +auto ArraySizeHelper(const T (&array)[N]) -> char (&)[N]; } // namespace macros_internal } // namespace absl #define ABSL_ARRAYSIZE(array) \ diff --git a/Firestore/third_party/abseil-cpp/absl/base/policy_checks.h b/Firestore/third_party/abseil-cpp/absl/base/policy_checks.h index 17c05c1..d634dac 100644 --- a/Firestore/third_party/abseil-cpp/absl/base/policy_checks.h +++ b/Firestore/third_party/abseil-cpp/absl/base/policy_checks.h @@ -46,15 +46,15 @@ // We support MSVC++ 14.0 update 2 and later. // This minimum will go up. -#if defined(_MSC_FULL_VER) && _MSC_FULL_VER < 190023918 -#error "This package requires Visual Studio 2015 Update 2 or higher" +#if defined(_MSC_FULL_VER) && _MSC_FULL_VER < 190023918 && !defined(__clang__) +#error "This package requires Visual Studio 2015 Update 2 or higher." #endif // We support gcc 4.7 and later. // This minimum will go up. #if defined(__GNUC__) && !defined(__clang__) #if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 7) -#error "This package requires gcc 4.7 or higher" +#error "This package requires gcc 4.7 or higher." #endif #endif @@ -62,7 +62,7 @@ // This corresponds to Apple Xcode version 4.5. // This minimum will go up. #if defined(__apple_build_version__) && __apple_build_version__ < 4211165 -#error "This package requires __apple_build_version__ of 4211165 or higher" +#error "This package requires __apple_build_version__ of 4211165 or higher." #endif // ----------------------------------------------------------------------------- @@ -96,4 +96,26 @@ #error "STLPort is not supported." #endif +// ----------------------------------------------------------------------------- +// `char` Size Check +// ----------------------------------------------------------------------------- + +// Abseil currently assumes CHAR_BIT == 8. If you would like to use Abseil on a +// platform where this is not the case, please provide us with the details about +// your platform so we can consider relaxing this requirement. +#if CHAR_BIT != 8 +#error "Abseil assumes CHAR_BIT == 8." +#endif + +// ----------------------------------------------------------------------------- +// `int` Size Check +// ----------------------------------------------------------------------------- + +// Abseil currently assumes that an int is 4 bytes. If you would like to use +// Abseil on a platform where this is not the case, please provide us with the +// details about your platform so we can consider relaxing this requirement. +#if INT_MAX < 2147483647 +#error "Abseil assumes that int is at least 4 bytes. " +#endif + #endif // ABSL_BASE_POLICY_CHECKS_H_ diff --git a/Firestore/third_party/abseil-cpp/absl/meta/type_traits.h b/Firestore/third_party/abseil-cpp/absl/meta/type_traits.h index f36a59a..ac5d8e1 100644 --- a/Firestore/third_party/abseil-cpp/absl/meta/type_traits.h +++ b/Firestore/third_party/abseil-cpp/absl/meta/type_traits.h @@ -150,6 +150,7 @@ struct is_trivially_destructible : std::integral_constant::value> { #ifdef ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE + private: static constexpr bool compliant = std::is_trivially_destructible::value == is_trivially_destructible::value; static_assert(compliant || std::is_trivially_destructible::value, @@ -199,6 +200,7 @@ struct is_trivially_default_constructible std::is_default_constructible::value && is_trivially_destructible::value> { #ifdef ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE + private: static constexpr bool compliant = std::is_trivially_default_constructible::value == is_trivially_default_constructible::value; @@ -230,6 +232,7 @@ struct is_trivially_copy_constructible std::is_copy_constructible::value && is_trivially_destructible::value> { #ifdef ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE + private: static constexpr bool compliant = std::is_trivially_copy_constructible::value == is_trivially_copy_constructible::value; @@ -262,6 +265,7 @@ struct is_trivially_copy_assignable : std::integral_constant::value> { #ifdef ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE + private: static constexpr bool compliant = std::is_trivially_copy_assignable::value == is_trivially_copy_assignable::value; diff --git a/Firestore/third_party/abseil-cpp/absl/numeric/int128.cc b/Firestore/third_party/abseil-cpp/absl/numeric/int128.cc index 00bf7f4..3688e5e 100644 --- a/Firestore/third_party/abseil-cpp/absl/numeric/int128.cc +++ b/Firestore/third_party/abseil-cpp/absl/numeric/int128.cc @@ -20,6 +20,7 @@ #include // NOLINT(readability/streams) #include #include +#include namespace absl { @@ -104,11 +105,15 @@ void DivModImpl(uint128 dividend, uint128 divisor, uint128* quotient_ret, } template -uint128 Initialize128FromFloat(T v) { +uint128 MakeUint128FromFloat(T v) { + static_assert(std::is_floating_point::value, ""); + // Rounding behavior is towards zero, same as for built-in types. // Undefined behavior if v is NaN or cannot fit into uint128. - assert(!std::isnan(v) && v > -1 && v < std::ldexp(static_cast(1), 128)); + assert(std::isfinite(v) && v > -1 && + (std::numeric_limits::max_exponent <= 128 || + v < std::ldexp(static_cast(1), 128))); if (v >= std::ldexp(static_cast(1), 64)) { uint64_t hi = static_cast(std::ldexp(v, -64)); @@ -120,28 +125,36 @@ uint128 Initialize128FromFloat(T v) { } } // namespace -uint128::uint128(float v) : uint128(Initialize128FromFloat(v)) {} -uint128::uint128(double v) : uint128(Initialize128FromFloat(v)) {} -uint128::uint128(long double v) : uint128(Initialize128FromFloat(v)) {} +uint128::uint128(float v) : uint128(MakeUint128FromFloat(v)) {} +uint128::uint128(double v) : uint128(MakeUint128FromFloat(v)) {} +uint128::uint128(long double v) : uint128(MakeUint128FromFloat(v)) {} -uint128& uint128::operator/=(uint128 other) { +uint128 operator/(uint128 lhs, uint128 rhs) { +#if defined(ABSL_HAVE_INTRINSIC_INT128) + return static_cast(lhs) / + static_cast(rhs); +#else // ABSL_HAVE_INTRINSIC_INT128 uint128 quotient = 0; uint128 remainder = 0; - DivModImpl(*this, other, "ient, &remainder); - *this = quotient; - return *this; + DivModImpl(lhs, rhs, "ient, &remainder); + return quotient; +#endif // ABSL_HAVE_INTRINSIC_INT128 } -uint128& uint128::operator%=(uint128 other) { +uint128 operator%(uint128 lhs, uint128 rhs) { +#if defined(ABSL_HAVE_INTRINSIC_INT128) + return static_cast(lhs) % + static_cast(rhs); +#else // ABSL_HAVE_INTRINSIC_INT128 uint128 quotient = 0; uint128 remainder = 0; - DivModImpl(*this, other, "ient, &remainder); - *this = remainder; - return *this; + DivModImpl(lhs, rhs, "ient, &remainder); + return remainder; +#endif // ABSL_HAVE_INTRINSIC_INT128 } -std::ostream& operator<<(std::ostream& o, uint128 b) { - std::ios_base::fmtflags flags = o.flags(); +namespace { +std::string Uint128ToFormattedString(uint128 v, std::ios_base::fmtflags flags) { // Select a divisor which is the largest power of the base < 2^64. uint128 div; int div_base_log; @@ -160,14 +173,14 @@ std::ostream& operator<<(std::ostream& o, uint128 b) { break; } - // Now piece together the uint128 representation from three chunks of - // the original value, each less than "div" and therefore representable - // as a uint64_t. + // Now piece together the uint128 representation from three chunks of the + // original value, each less than "div" and therefore representable as a + // uint64_t. std::ostringstream os; std::ios_base::fmtflags copy_mask = std::ios::basefield | std::ios::showbase | std::ios::uppercase; os.setf(flags & copy_mask, copy_mask); - uint128 high = b; + uint128 high = v; uint128 low; DivModImpl(high, div, &high, &low); uint128 mid; @@ -182,25 +195,31 @@ std::ostream& operator<<(std::ostream& o, uint128 b) { os << std::noshowbase << std::setfill('0') << std::setw(div_base_log); } os << Uint128Low64(low); - std::string rep = os.str(); + return os.str(); +} + +} // namespace + +std::ostream& operator<<(std::ostream& os, uint128 v) { + std::ios_base::fmtflags flags = os.flags(); + std::string rep = Uint128ToFormattedString(v, flags); // Add the requisite padding. - std::streamsize width = o.width(0); + std::streamsize width = os.width(0); if (static_cast(width) > rep.size()) { std::ios::fmtflags adjustfield = flags & std::ios::adjustfield; if (adjustfield == std::ios::left) { - rep.append(width - rep.size(), o.fill()); + rep.append(width - rep.size(), os.fill()); } else if (adjustfield == std::ios::internal && (flags & std::ios::showbase) && - (flags & std::ios::basefield) == std::ios::hex && b != 0) { - rep.insert(2, width - rep.size(), o.fill()); + (flags & std::ios::basefield) == std::ios::hex && v != 0) { + rep.insert(2, width - rep.size(), os.fill()); } else { - rep.insert(0, width - rep.size(), o.fill()); + rep.insert(0, width - rep.size(), os.fill()); } } - // Stream the final representation in a single "<<" call. - return o << rep; + return os << rep; } } // namespace absl diff --git a/Firestore/third_party/abseil-cpp/absl/numeric/int128.h b/Firestore/third_party/abseil-cpp/absl/numeric/int128.h index d87cbbd..bc7dbb4 100644 --- a/Firestore/third_party/abseil-cpp/absl/numeric/int128.h +++ b/Firestore/third_party/abseil-cpp/absl/numeric/int128.h @@ -17,9 +17,10 @@ // File: int128.h // ----------------------------------------------------------------------------- // -// This header file defines 128-bit integer types. Currently, this file defines -// `uint128`, an unsigned 128-bit integer; a signed 128-bit integer is -// forthcoming. +// This header file defines 128-bit integer types. +// +// Currently, this file defines `uint128`, an unsigned 128-bit integer; a signed +// 128-bit integer is forthcoming. #ifndef ABSL_NUMERIC_INT128_H_ #define ABSL_NUMERIC_INT128_H_ @@ -37,14 +38,15 @@ namespace absl { + // uint128 // // An unsigned 128-bit integer type. The API is meant to mimic an intrinsic type // as closely as is practical, including exhibiting undefined behavior in // analogous cases (e.g. division by zero). This type is intended to be a // drop-in replacement once C++ supports an intrinsic `uint128_t` type; when -// that occurs, existing uses of `uint128` will continue to work using that new -// type. +// that occurs, existing well-behaved uses of `uint128` will continue to work +// using that new type. // // Note: code written with this type will continue to compile once `uint128_t` // is introduced, provided the replacement helper functions @@ -62,23 +64,30 @@ namespace absl { // However, a `uint128` differs from intrinsic integral types in the following // ways: // -// * Errors on implicit conversions that does not preserve value (such as +// * Errors on implicit conversions that do not preserve value (such as // loss of precision when converting to float values). // * Requires explicit construction from and conversion to floating point // types. // * Conversion to integral types requires an explicit static_cast() to // mimic use of the `-Wnarrowing` compiler flag. +// * The alignment requirement of `uint128` may differ from that of an +// intrinsic 128-bit integer type depending on platform and build +// configuration. // // Example: // -// float y = absl::kuint128max; // Error. uint128 cannot be implicitly -// // converted to float. +// float y = absl::Uint128Max(); // Error. uint128 cannot be implicitly +// // converted to float. // // absl::uint128 v; -// absl::uint64_t i = v; // Error -// absl::uint64_t i = static_cast(v); // OK +// uint64_t i = v; // Error +// uint64_t i = static_cast(v); // OK // -class alignas(16) uint128 { +class +#if defined(ABSL_HAVE_INTRINSIC_INT128) + alignas(unsigned __int128) +#endif // ABSL_HAVE_INTRINSIC_INT128 + uint128 { public: uint128() = default; @@ -175,10 +184,15 @@ class alignas(16) uint128 { // Example: // // absl::uint128 big = absl::MakeUint128(1, 0); - friend constexpr uint128 MakeUint128(uint64_t top, uint64_t bottom); + friend constexpr uint128 MakeUint128(uint64_t high, uint64_t low); + + // Uint128Max() + // + // Returns the highest value for a 128-bit unsigned integer. + friend constexpr uint128 Uint128Max(); private: - constexpr uint128(uint64_t top, uint64_t bottom); + constexpr uint128(uint64_t high, uint64_t low); // TODO(strel) Update implementation to use __int128 once all users of // uint128 are fixed to not depend on alignof(uint128) == 8. Also add @@ -195,10 +209,13 @@ class alignas(16) uint128 { #endif // byte order }; +// Prefer to use the constexpr `Uint128Max()`. +// +// TODO(absl-team) deprecate kuint128max once migration tool is released. extern const uint128 kuint128max; // allow uint128 to be logged -extern std::ostream& operator<<(std::ostream& o, uint128 b); +std::ostream& operator<<(std::ostream& os, uint128 v); // TODO(strel) add operator>>(std::istream&, uint128) @@ -208,8 +225,13 @@ extern std::ostream& operator<<(std::ostream& o, uint128 b); // Implementation details follow // -------------------------------------------------------------------------- -constexpr uint128 MakeUint128(uint64_t top, uint64_t bottom) { - return uint128(top, bottom); +constexpr uint128 MakeUint128(uint64_t high, uint64_t low) { + return uint128(high, low); +} + +constexpr uint128 Uint128Max() { + return uint128(std::numeric_limits::max(), + std::numeric_limits::max()); } // Assignment from integer types. @@ -249,34 +271,49 @@ inline uint128& uint128::operator=(unsigned __int128 v) { } #endif // ABSL_HAVE_INTRINSIC_INT128 -// Shift and arithmetic operators. +// Arithmetic operators. -inline uint128 operator<<(uint128 lhs, int amount) { - return uint128(lhs) <<= amount; +uint128 operator<<(uint128 lhs, int amount); +uint128 operator>>(uint128 lhs, int amount); +uint128 operator+(uint128 lhs, uint128 rhs); +uint128 operator-(uint128 lhs, uint128 rhs); +uint128 operator*(uint128 lhs, uint128 rhs); +uint128 operator/(uint128 lhs, uint128 rhs); +uint128 operator%(uint128 lhs, uint128 rhs); + +inline uint128& uint128::operator<<=(int amount) { + *this = *this << amount; + return *this; } -inline uint128 operator>>(uint128 lhs, int amount) { - return uint128(lhs) >>= amount; +inline uint128& uint128::operator>>=(int amount) { + *this = *this >> amount; + return *this; } -inline uint128 operator+(uint128 lhs, uint128 rhs) { - return uint128(lhs) += rhs; +inline uint128& uint128::operator+=(uint128 other) { + *this = *this + other; + return *this; } -inline uint128 operator-(uint128 lhs, uint128 rhs) { - return uint128(lhs) -= rhs; +inline uint128& uint128::operator-=(uint128 other) { + *this = *this - other; + return *this; } -inline uint128 operator*(uint128 lhs, uint128 rhs) { - return uint128(lhs) *= rhs; +inline uint128& uint128::operator*=(uint128 other) { + *this = *this * other; + return *this; } -inline uint128 operator/(uint128 lhs, uint128 rhs) { - return uint128(lhs) /= rhs; +inline uint128& uint128::operator/=(uint128 other) { + *this = *this / other; + return *this; } -inline uint128 operator%(uint128 lhs, uint128 rhs) { - return uint128(lhs) %= rhs; +inline uint128& uint128::operator%=(uint128 other) { + *this = *this % other; + return *this; } constexpr uint64_t Uint128Low64(uint128 v) { return v.lo_; } @@ -287,56 +324,62 @@ constexpr uint64_t Uint128High64(uint128 v) { return v.hi_; } #if defined(ABSL_IS_LITTLE_ENDIAN) -constexpr uint128::uint128(uint64_t top, uint64_t bottom) - : lo_(bottom), hi_(top) {} +constexpr uint128::uint128(uint64_t high, uint64_t low) + : lo_{low}, hi_{high} {} constexpr uint128::uint128(int v) - : lo_(v), hi_(v < 0 ? std::numeric_limits::max() : 0) {} + : lo_{static_cast(v)}, + hi_{v < 0 ? std::numeric_limits::max() : 0} {} constexpr uint128::uint128(long v) // NOLINT(runtime/int) - : lo_(v), hi_(v < 0 ? std::numeric_limits::max() : 0) {} + : lo_{static_cast(v)}, + hi_{v < 0 ? std::numeric_limits::max() : 0} {} constexpr uint128::uint128(long long v) // NOLINT(runtime/int) - : lo_(v), hi_(v < 0 ? std::numeric_limits::max() : 0) {} + : lo_{static_cast(v)}, + hi_{v < 0 ? std::numeric_limits::max() : 0} {} -constexpr uint128::uint128(unsigned int v) : lo_(v), hi_(0) {} +constexpr uint128::uint128(unsigned int v) : lo_{v}, hi_{0} {} // NOLINTNEXTLINE(runtime/int) -constexpr uint128::uint128(unsigned long v) : lo_(v), hi_(0) {} +constexpr uint128::uint128(unsigned long v) : lo_{v}, hi_{0} {} // NOLINTNEXTLINE(runtime/int) -constexpr uint128::uint128(unsigned long long v) : lo_(v), hi_(0) {} +constexpr uint128::uint128(unsigned long long v) : lo_{v}, hi_{0} {} #ifdef ABSL_HAVE_INTRINSIC_INT128 constexpr uint128::uint128(__int128 v) - : lo_(static_cast(v & ~uint64_t{0})), - hi_(static_cast(static_cast(v) >> 64)) {} + : lo_{static_cast(v & ~uint64_t{0})}, + hi_{static_cast(static_cast(v) >> 64)} {} constexpr uint128::uint128(unsigned __int128 v) - : lo_(static_cast(v & ~uint64_t{0})), - hi_(static_cast(v >> 64)) {} + : lo_{static_cast(v & ~uint64_t{0})}, + hi_{static_cast(v >> 64)} {} #endif // ABSL_HAVE_INTRINSIC_INT128 #elif defined(ABSL_IS_BIG_ENDIAN) -constexpr uint128::uint128(uint64_t top, uint64_t bottom) - : hi_(top), lo_(bottom) {} +constexpr uint128::uint128(uint64_t high, uint64_t low) + : hi_{high}, lo_{low} {} constexpr uint128::uint128(int v) - : hi_(v < 0 ? std::numeric_limits::max() : 0), lo_(v) {} + : hi_{v < 0 ? std::numeric_limits::max() : 0}, + lo_{static_cast(v)} {} constexpr uint128::uint128(long v) // NOLINT(runtime/int) - : hi_(v < 0 ? std::numeric_limits::max() : 0), lo_(v) {} + : hi_{v < 0 ? std::numeric_limits::max() : 0}, + lo_{static_cast(v)} {} constexpr uint128::uint128(long long v) // NOLINT(runtime/int) - : hi_(v < 0 ? std::numeric_limits::max() : 0), lo_(v) {} + : hi_{v < 0 ? std::numeric_limits::max() : 0}, + lo_{static_cast(v)} {} -constexpr uint128::uint128(unsigned int v) : hi_(0), lo_(v) {} +constexpr uint128::uint128(unsigned int v) : hi_{0}, lo_{v} {} // NOLINTNEXTLINE(runtime/int) -constexpr uint128::uint128(unsigned long v) : hi_(0), lo_(v) {} +constexpr uint128::uint128(unsigned long v) : hi_{0}, lo_{v} {} // NOLINTNEXTLINE(runtime/int) -constexpr uint128::uint128(unsigned long long v) : hi_(0), lo_(v) {} +constexpr uint128::uint128(unsigned long long v) : hi_{0}, lo_{v} {} #ifdef ABSL_HAVE_INTRINSIC_INT128 constexpr uint128::uint128(__int128 v) - : hi_(static_cast(static_cast(v) >> 64)), - lo_(static_cast(v & ~uint64_t{0})) {} + : hi_{static_cast(static_cast(v) >> 64)}, + lo_{static_cast(v & ~uint64_t{0})} {} constexpr uint128::uint128(unsigned __int128 v) - : hi_(static_cast(v >> 64)), - lo_(static_cast(v & ~uint64_t{0})) {} + : hi_{static_cast(v >> 64)}, + lo_{static_cast(v & ~uint64_t{0})} {} #endif // ABSL_HAVE_INTRINSIC_INT128 #else // byte order @@ -460,13 +503,10 @@ inline bool operator>=(uint128 lhs, uint128 rhs) { // Unary operators. inline uint128 operator-(uint128 val) { - const uint64_t hi_flip = ~Uint128High64(val); - const uint64_t lo_flip = ~Uint128Low64(val); - const uint64_t lo_add = lo_flip + 1; - if (lo_add < lo_flip) { - return MakeUint128(hi_flip + 1, lo_add); - } - return MakeUint128(hi_flip, lo_add); + uint64_t hi = ~Uint128High64(val); + uint64_t lo = ~Uint128Low64(val) + 1; + if (lo == 0) ++hi; // carry + return MakeUint128(hi, lo); } inline bool operator!(uint128 val) { @@ -512,88 +552,72 @@ inline uint128& uint128::operator^=(uint128 other) { return *this; } -// Shift and arithmetic assign operators. - -inline uint128& uint128::operator<<=(int amount) { - // Shifts of >= 128 are undefined. - assert(amount < 128); +// Arithmetic operators. +inline uint128 operator<<(uint128 lhs, int amount) { // uint64_t shifts of >= 64 are undefined, so we will need some // special-casing. if (amount < 64) { if (amount != 0) { - hi_ = (hi_ << amount) | (lo_ >> (64 - amount)); - lo_ = lo_ << amount; + return MakeUint128( + (Uint128High64(lhs) << amount) | (Uint128Low64(lhs) >> (64 - amount)), + Uint128Low64(lhs) << amount); } - } else { - hi_ = lo_ << (amount - 64); - lo_ = 0; + return lhs; } - return *this; + return MakeUint128(Uint128Low64(lhs) << (amount - 64), 0); } -inline uint128& uint128::operator>>=(int amount) { - // Shifts of >= 128 are undefined. - assert(amount < 128); - +inline uint128 operator>>(uint128 lhs, int amount) { // uint64_t shifts of >= 64 are undefined, so we will need some // special-casing. if (amount < 64) { if (amount != 0) { - lo_ = (lo_ >> amount) | (hi_ << (64 - amount)); - hi_ = hi_ >> amount; + return MakeUint128(Uint128High64(lhs) >> amount, + (Uint128Low64(lhs) >> amount) | + (Uint128High64(lhs) << (64 - amount))); } - } else { - lo_ = hi_ >> (amount - 64); - hi_ = 0; + return lhs; } - return *this; + return MakeUint128(0, Uint128High64(lhs) >> (amount - 64)); } -inline uint128& uint128::operator+=(uint128 other) { - hi_ += other.hi_; - uint64_t lolo = lo_ + other.lo_; - if (lolo < lo_) - ++hi_; - lo_ = lolo; - return *this; +inline uint128 operator+(uint128 lhs, uint128 rhs) { + uint128 result = MakeUint128(Uint128High64(lhs) + Uint128High64(rhs), + Uint128Low64(lhs) + Uint128Low64(rhs)); + if (Uint128Low64(result) < Uint128Low64(lhs)) { // check for carry + return MakeUint128(Uint128High64(result) + 1, Uint128Low64(result)); + } + return result; } -inline uint128& uint128::operator-=(uint128 other) { - hi_ -= other.hi_; - if (other.lo_ > lo_) --hi_; - lo_ -= other.lo_; - return *this; +inline uint128 operator-(uint128 lhs, uint128 rhs) { + uint128 result = MakeUint128(Uint128High64(lhs) - Uint128High64(rhs), + Uint128Low64(lhs) - Uint128Low64(rhs)); + if (Uint128Low64(lhs) < Uint128Low64(rhs)) { // check for carry + return MakeUint128(Uint128High64(result) - 1, Uint128Low64(result)); + } + return result; } -inline uint128& uint128::operator*=(uint128 other) { +inline uint128 operator*(uint128 lhs, uint128 rhs) { #if defined(ABSL_HAVE_INTRINSIC_INT128) // TODO(strel) Remove once alignment issues are resolved and unsigned __int128 // can be used for uint128 storage. - *this = static_cast(*this) * - static_cast(other); - return *this; + return static_cast(lhs) * + static_cast(rhs); #else // ABSL_HAVE_INTRINSIC128 - uint64_t a96 = hi_ >> 32; - uint64_t a64 = hi_ & 0xffffffff; - uint64_t a32 = lo_ >> 32; - uint64_t a00 = lo_ & 0xffffffff; - uint64_t b96 = other.hi_ >> 32; - uint64_t b64 = other.hi_ & 0xffffffff; - uint64_t b32 = other.lo_ >> 32; - uint64_t b00 = other.lo_ & 0xffffffff; - // multiply [a96 .. a00] x [b96 .. b00] - // terms higher than c96 disappear off the high side - // terms c96 and c64 are safe to ignore carry bit - uint64_t c96 = a96 * b00 + a64 * b32 + a32 * b64 + a00 * b96; - uint64_t c64 = a64 * b00 + a32 * b32 + a00 * b64; - this->hi_ = (c96 << 32) + c64; - this->lo_ = 0; - // add terms after this one at a time to capture carry - *this += uint128(a32 * b00) << 32; - *this += uint128(a00 * b32) << 32; - *this += a00 * b00; - return *this; + uint64_t a32 = Uint128Low64(lhs) >> 32; + uint64_t a00 = Uint128Low64(lhs) & 0xffffffff; + uint64_t b32 = Uint128Low64(rhs) >> 32; + uint64_t b00 = Uint128Low64(rhs) & 0xffffffff; + uint128 result = + MakeUint128(Uint128High64(lhs) * Uint128Low64(rhs) + + Uint128Low64(lhs) * Uint128High64(rhs) + a32 * b32, + a00 * b00); + result += uint128(a32 * b00) << 32; + result += uint128(a00 * b32) << 32; + return result; #endif // ABSL_HAVE_INTRINSIC128 } diff --git a/Firestore/third_party/abseil-cpp/absl/numeric/int128_have_intrinsic.inc b/Firestore/third_party/abseil-cpp/absl/numeric/int128_have_intrinsic.inc index 49bde07..ee2a093 100644 --- a/Firestore/third_party/abseil-cpp/absl/numeric/int128_have_intrinsic.inc +++ b/Firestore/third_party/abseil-cpp/absl/numeric/int128_have_intrinsic.inc @@ -1,3 +1,18 @@ -// This file will contain :int128 implementation details that depend on internal -// representation when ABSL_HAVE_INTRINSIC_INT128 is defined. This file will be +// +// 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. + +// This file contains :int128 implementation details that depend on internal +// representation when ABSL_HAVE_INTRINSIC_INT128 is defined. This file is // included by int128.h. diff --git a/Firestore/third_party/abseil-cpp/absl/numeric/int128_no_intrinsic.inc b/Firestore/third_party/abseil-cpp/absl/numeric/int128_no_intrinsic.inc index 2dbff2b..0d0b3cf 100644 --- a/Firestore/third_party/abseil-cpp/absl/numeric/int128_no_intrinsic.inc +++ b/Firestore/third_party/abseil-cpp/absl/numeric/int128_no_intrinsic.inc @@ -1,3 +1,18 @@ -// This file will contain :int128 implementation details that depend on internal +// +// 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. + +// This file contains :int128 implementation details that depend on internal // representation when ABSL_HAVE_INTRINSIC_INT128 is *not* defined. This file -// will be included by int128.h. +// is included by int128.h. diff --git a/Firestore/third_party/abseil-cpp/absl/numeric/int128_test.cc b/Firestore/third_party/abseil-cpp/absl/numeric/int128_test.cc index d674cb1..79bcca9 100644 --- a/Firestore/third_party/abseil-cpp/absl/numeric/int128_test.cc +++ b/Firestore/third_party/abseil-cpp/absl/numeric/int128_test.cc @@ -110,7 +110,7 @@ TEST(Uint128, AllTests) { absl::uint128 big = absl::MakeUint128(2000, 2); absl::uint128 big_minus_one = absl::MakeUint128(2000, 1); absl::uint128 bigger = absl::MakeUint128(2001, 1); - absl::uint128 biggest = absl::kuint128max; + absl::uint128 biggest = absl::Uint128Max(); absl::uint128 high_low = absl::MakeUint128(1, 0); absl::uint128 low_high = absl::MakeUint128(0, std::numeric_limits::max()); @@ -227,8 +227,10 @@ TEST(Uint128, AllTests) { EXPECT_EQ(big, -(-big)); EXPECT_EQ(two, -((-one) - 1)); - EXPECT_EQ(absl::kuint128max, -one); + EXPECT_EQ(absl::Uint128Max(), -one); EXPECT_EQ(zero, -zero); + + EXPECT_EQ(absl::Uint128Max(), absl::kuint128max); } TEST(Uint128, ConversionTests) { diff --git a/Firestore/third_party/abseil-cpp/absl/strings/escaping_test.cc b/Firestore/third_party/abseil-cpp/absl/strings/escaping_test.cc index e87f101..982989b 100644 --- a/Firestore/third_party/abseil-cpp/absl/strings/escaping_test.cc +++ b/Firestore/third_party/abseil-cpp/absl/strings/escaping_test.cc @@ -22,6 +22,7 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "absl/container/fixed_array.h" #include "absl/strings/str_cat.h" #include "absl/strings/internal/escaping_test_common.inc" diff --git a/Firestore/third_party/abseil-cpp/absl/strings/internal/stl_type_traits.h b/Firestore/third_party/abseil-cpp/absl/strings/internal/stl_type_traits.h index 8c3d877..04c4a53 100644 --- a/Firestore/third_party/abseil-cpp/absl/strings/internal/stl_type_traits.h +++ b/Firestore/third_party/abseil-cpp/absl/strings/internal/stl_type_traits.h @@ -79,31 +79,48 @@ struct IsSTLContainer template class T, typename = void> struct IsBaseOfSpecializationImpl : std::false_type {}; -// IsBaseOfSpecializationImpl must have three partial specializations, -// because we must only compare templates that take the same number of -// arguments. Otherwise, for example, std::vector can be compared with std::map, -// and fail to compile because of too few or too many template arguments. -// -// We must also SFINAE on the existence of an allocator_type. Otherwise, we may -// try to compare, for example, a std::pair with a -// std::vector. This would fail to compile, because -// of expected properties of the type passed in as the allocator. -template