Commit 402e1319 by Copybara-Service

Merge pull request #1403 from AtariDreams:c++11

PiperOrigin-RevId: 511539869
Change-Id: I32d5e91537b078691988e7e6d3244c682eb8d7d2
parents 277af61c 6247f0e9
...@@ -342,7 +342,7 @@ class FixedArray { ...@@ -342,7 +342,7 @@ class FixedArray {
// Relational operators. Equality operators are elementwise using // Relational operators. Equality operators are elementwise using
// `operator==`, while order operators order FixedArrays lexicographically. // `operator==`, while order operators order FixedArrays lexicographically.
friend bool operator==(const FixedArray& lhs, const FixedArray& rhs) { friend bool operator==(const FixedArray& lhs, const FixedArray& rhs) {
return absl::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
} }
friend bool operator!=(const FixedArray& lhs, const FixedArray& rhs) { friend bool operator!=(const FixedArray& lhs, const FixedArray& rhs) {
......
...@@ -843,7 +843,7 @@ bool operator==(const absl::InlinedVector<T, N, A>& a, ...@@ -843,7 +843,7 @@ bool operator==(const absl::InlinedVector<T, N, A>& a,
const absl::InlinedVector<T, N, A>& b) { const absl::InlinedVector<T, N, A>& b) {
auto a_data = a.data(); auto a_data = a.data();
auto b_data = b.data(); auto b_data = b.data();
return absl::equal(a_data, a_data + a.size(), b_data, b_data + b.size()); return std::equal(a_data, a_data + a.size(), b_data, b_data + b.size());
} }
// `operator!=(...)` // `operator!=(...)`
......
...@@ -460,9 +460,7 @@ inline constexpr size_t CordBuffer::MaximumPayload() { ...@@ -460,9 +460,7 @@ inline constexpr size_t CordBuffer::MaximumPayload() {
} }
inline constexpr size_t CordBuffer::MaximumPayload(size_t block_size) { inline constexpr size_t CordBuffer::MaximumPayload(size_t block_size) {
// TODO(absl-team): Use std::min when C++11 support is dropped. return (std::min)(kCustomLimit, block_size) - cord_internal::kFlatOverhead;
return (kCustomLimit < block_size ? kCustomLimit : block_size) -
cord_internal::kFlatOverhead;
} }
inline CordBuffer CordBuffer::CreateWithDefaultLimit(size_t capacity) { inline CordBuffer CordBuffer::CreateWithDefaultLimit(size_t capacity) {
......
...@@ -96,13 +96,6 @@ inline bool IsValidDivisor(double d) { ...@@ -96,13 +96,6 @@ inline bool IsValidDivisor(double d) {
return d != 0.0; return d != 0.0;
} }
// Can't use std::round() because it is only available in C++11.
// Note that we ignore the possibility of floating-point over/underflow.
template <typename Double>
inline double Round(Double d) {
return d < 0 ? std::ceil(d - 0.5) : std::floor(d + 0.5);
}
// *sec may be positive or negative. *ticks must be in the range // *sec may be positive or negative. *ticks must be in the range
// -kTicksPerSecond < *ticks < kTicksPerSecond. If *ticks is negative it // -kTicksPerSecond < *ticks < kTicksPerSecond. If *ticks is negative it
// will be normalized to a positive value by adjusting *sec accordingly. // will be normalized to a positive value by adjusting *sec accordingly.
...@@ -260,7 +253,7 @@ inline Duration ScaleDouble(Duration d, double r) { ...@@ -260,7 +253,7 @@ inline Duration ScaleDouble(Duration d, double r) {
double lo_frac = std::modf(lo_doub, &lo_int); double lo_frac = std::modf(lo_doub, &lo_int);
// Rolls lo into hi if necessary. // Rolls lo into hi if necessary.
int64_t lo64 = Round(lo_frac * kTicksPerSecond); int64_t lo64 = std::round(lo_frac * kTicksPerSecond);
Duration ans; Duration ans;
if (!SafeAddRepHi(hi_int, lo_int, &ans)) return ans; if (!SafeAddRepHi(hi_int, lo_int, &ans)) return ans;
...@@ -741,7 +734,7 @@ void AppendNumberUnit(std::string* out, double n, DisplayUnit unit) { ...@@ -741,7 +734,7 @@ void AppendNumberUnit(std::string* out, double n, DisplayUnit unit) {
char buf[kBufferSize]; // also large enough to hold integer part char buf[kBufferSize]; // also large enough to hold integer part
char* ep = buf + sizeof(buf); char* ep = buf + sizeof(buf);
double d = 0; double d = 0;
int64_t frac_part = Round(std::modf(n, &d) * unit.pow10); int64_t frac_part = std::round(std::modf(n, &d) * unit.pow10);
int64_t int_part = d; int64_t int_part = d;
if (int_part != 0 || frac_part != 0) { if (int_part != 0 || frac_part != 0) {
char* bp = Format64(ep, 0, int_part); // always < 1000 char* bp = Format64(ep, 0, int_part); // always < 1000
......
...@@ -88,7 +88,7 @@ using EnableIfMutable = ...@@ -88,7 +88,7 @@ using EnableIfMutable =
template <template <typename> class SpanT, typename T> template <template <typename> class SpanT, typename T>
bool EqualImpl(SpanT<T> a, SpanT<T> b) { bool EqualImpl(SpanT<T> a, SpanT<T> b) {
static_assert(std::is_const<T>::value, ""); static_assert(std::is_const<T>::value, "");
return absl::equal(a.begin(), a.end(), b.begin(), b.end()); return std::equal(a.begin(), a.end(), b.begin(), b.end());
} }
template <template <typename> class SpanT, typename T> template <template <typename> class SpanT, typename T>
......
...@@ -877,8 +877,8 @@ struct IndexOfConstructedType< ...@@ -877,8 +877,8 @@ struct IndexOfConstructedType<
template <std::size_t... Is> template <std::size_t... Is>
struct ContainsVariantNPos struct ContainsVariantNPos
: absl::negation<std::is_same< // NOLINT : absl::negation<std::is_same< // NOLINT
absl::integer_sequence<bool, 0 <= Is...>, std::integer_sequence<bool, 0 <= Is...>,
absl::integer_sequence<bool, Is != absl::variant_npos...>>> {}; std::integer_sequence<bool, Is != absl::variant_npos...>>> {};
template <class Op, class... QualifiedVariants> template <class Op, class... QualifiedVariants>
using RawVisitResult = using RawVisitResult =
......
...@@ -97,9 +97,9 @@ struct StructorListener { ...@@ -97,9 +97,9 @@ struct StructorListener {
// 4522: multiple assignment operators specified // 4522: multiple assignment operators specified
// We wrote multiple of them to test that the correct overloads are selected. // We wrote multiple of them to test that the correct overloads are selected.
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning( push ) #pragma warning(push)
#pragma warning( disable : 4521) #pragma warning(disable : 4521)
#pragma warning( disable : 4522) #pragma warning(disable : 4522)
#endif #endif
struct Listenable { struct Listenable {
static StructorListener* listener; static StructorListener* listener;
...@@ -133,20 +133,11 @@ struct Listenable { ...@@ -133,20 +133,11 @@ struct Listenable {
~Listenable() { ++listener->destruct; } ~Listenable() { ++listener->destruct; }
}; };
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning( pop ) #pragma warning(pop)
#endif #endif
StructorListener* Listenable::listener = nullptr; StructorListener* Listenable::listener = nullptr;
// ABSL_HAVE_NO_CONSTEXPR_INITIALIZER_LIST is defined to 1 when the standard
// library implementation doesn't marked initializer_list's default constructor
// constexpr. The C++11 standard doesn't specify constexpr on it, but C++14
// added it. However, libstdc++ 4.7 marked it constexpr.
#if defined(_LIBCPP_VERSION) && \
(_LIBCPP_STD_VER <= 11 || defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR))
#define ABSL_HAVE_NO_CONSTEXPR_INITIALIZER_LIST 1
#endif
struct ConstexprType { struct ConstexprType {
enum CtorTypes { enum CtorTypes {
kCtorDefault, kCtorDefault,
...@@ -156,10 +147,8 @@ struct ConstexprType { ...@@ -156,10 +147,8 @@ struct ConstexprType {
}; };
constexpr ConstexprType() : x(kCtorDefault) {} constexpr ConstexprType() : x(kCtorDefault) {}
constexpr explicit ConstexprType(int i) : x(kCtorInt) {} constexpr explicit ConstexprType(int i) : x(kCtorInt) {}
#ifndef ABSL_HAVE_NO_CONSTEXPR_INITIALIZER_LIST
constexpr ConstexprType(std::initializer_list<int> il) constexpr ConstexprType(std::initializer_list<int> il)
: x(kCtorInitializerList) {} : x(kCtorInitializerList) {}
#endif
constexpr ConstexprType(const char*) // NOLINT(runtime/explicit) constexpr ConstexprType(const char*) // NOLINT(runtime/explicit)
: x(kCtorConstChar) {} : x(kCtorConstChar) {}
int x; int x;
...@@ -352,11 +341,9 @@ TEST(optionalTest, InPlaceConstructor) { ...@@ -352,11 +341,9 @@ TEST(optionalTest, InPlaceConstructor) {
constexpr absl::optional<ConstexprType> opt1{absl::in_place_t(), 1}; constexpr absl::optional<ConstexprType> opt1{absl::in_place_t(), 1};
static_assert(opt1, ""); static_assert(opt1, "");
static_assert((*opt1).x == ConstexprType::kCtorInt, ""); static_assert((*opt1).x == ConstexprType::kCtorInt, "");
#ifndef ABSL_HAVE_NO_CONSTEXPR_INITIALIZER_LIST
constexpr absl::optional<ConstexprType> opt2{absl::in_place_t(), {1, 2}}; constexpr absl::optional<ConstexprType> opt2{absl::in_place_t(), {1, 2}};
static_assert(opt2, ""); static_assert(opt2, "");
static_assert((*opt2).x == ConstexprType::kCtorInitializerList, ""); static_assert((*opt2).x == ConstexprType::kCtorInitializerList, "");
#endif
EXPECT_FALSE((std::is_constructible<absl::optional<ConvertsFromInPlaceT>, EXPECT_FALSE((std::is_constructible<absl::optional<ConvertsFromInPlaceT>,
absl::in_place_t>::value)); absl::in_place_t>::value));
...@@ -1000,9 +987,8 @@ TEST(optionalTest, PointerStuff) { ...@@ -1000,9 +987,8 @@ TEST(optionalTest, PointerStuff) {
// Skip that test to make the build green again when using the old compiler. // Skip that test to make the build green again when using the old compiler.
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59296 is fixed in 4.9.1. // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59296 is fixed in 4.9.1.
#if defined(__GNUC__) && !defined(__clang__) #if defined(__GNUC__) && !defined(__clang__)
#define GCC_VERSION (__GNUC__ * 10000 \ #define GCC_VERSION \
+ __GNUC_MINOR__ * 100 \ (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
+ __GNUC_PATCHLEVEL__)
#if GCC_VERSION < 40901 #if GCC_VERSION < 40901
#define ABSL_SKIP_OVERLOAD_TEST_DUE_TO_GCC_BUG #define ABSL_SKIP_OVERLOAD_TEST_DUE_TO_GCC_BUG
#endif #endif
...@@ -1214,7 +1200,6 @@ void optionalTest_Comparisons_EXPECT_GREATER(T x, U y) { ...@@ -1214,7 +1200,6 @@ void optionalTest_Comparisons_EXPECT_GREATER(T x, U y) {
EXPECT_TRUE(x >= y); EXPECT_TRUE(x >= y);
} }
template <typename T, typename U, typename V> template <typename T, typename U, typename V>
void TestComparisons() { void TestComparisons() {
absl::optional<T> ae, a2{2}, a4{4}; absl::optional<T> ae, a2{2}, a4{4};
...@@ -1307,7 +1292,6 @@ TEST(optionalTest, Comparisons) { ...@@ -1307,7 +1292,6 @@ TEST(optionalTest, Comparisons) {
EXPECT_TRUE(e1 == e2); EXPECT_TRUE(e1 == e2);
} }
TEST(optionalTest, SwapRegression) { TEST(optionalTest, SwapRegression) {
StructorListener listener; StructorListener listener;
Listenable::listener = &listener; Listenable::listener = &listener;
......
...@@ -191,7 +191,7 @@ TEST(IntSpan, SpanOfDerived) { ...@@ -191,7 +191,7 @@ TEST(IntSpan, SpanOfDerived) {
} }
void TestInitializerList(absl::Span<const int> s, const std::vector<int>& v) { void TestInitializerList(absl::Span<const int> s, const std::vector<int>& v) {
EXPECT_TRUE(absl::equal(s.begin(), s.end(), v.begin(), v.end())); EXPECT_TRUE(std::equal(s.begin(), s.end(), v.begin(), v.end()));
} }
TEST(ConstIntSpan, InitializerListConversion) { TEST(ConstIntSpan, InitializerListConversion) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment