Skip to content

Commit

Permalink
[CodeHealth] Replace std::is_...<>::value -> std::is_..._v<> in base/
Browse files Browse the repository at this point in the history
Patch 2/x:
  * android/
  * apple/
  * debug/
  * functional/
  * memory/
  * task/

Automatically processed with perl on selected files:

perl -pi -e 's/std::is_(\w+?)<(.*?)>::value\b/std::is_\1_v<\2>/g'

Bug: None
Change-Id: If19e724a88ecef5ef83783695984c23fbbd33f4b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4934070
Reviewed-by: Francois Pierre Doray <fdoray@chromium.org>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Andrew Rayskiy <greengrape@google.com>
Cr-Commit-Position: refs/heads/main@{#1210791}
  • Loading branch information
Andrew Rayskiy authored and Chromium LUCI CQ committed Oct 17, 2023
1 parent 63d4a16 commit b42fe75
Show file tree
Hide file tree
Showing 19 changed files with 93 additions and 106 deletions.
22 changes: 11 additions & 11 deletions base/android/scoped_java_ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class JavaRef : public JavaRef<jobject> {
// template parameter.
template <typename ElementType,
typename T_ = T,
typename = std::enable_if_t<std::is_same<T_, jobjectArray>::value>>
typename = std::enable_if_t<std::is_same_v<T_, jobjectArray>>>
JavaObjectArrayReader<ElementType> ReadElements() const {
return JavaObjectArrayReader<ElementType>(*this);
}
Expand Down Expand Up @@ -192,7 +192,7 @@ class ScopedJavaLocalRef : public JavaRef<T> {

// Copy conversion constructor.
template <typename U,
typename = std::enable_if_t<std::is_convertible<U, T>::value>>
typename = std::enable_if_t<std::is_convertible_v<U, T>>>
ScopedJavaLocalRef(const ScopedJavaLocalRef<U>& other) : env_(other.env_) {
JavaRef<T>::SetNewLocalRef(env_, other.obj());
}
Expand All @@ -205,7 +205,7 @@ class ScopedJavaLocalRef : public JavaRef<T> {

// Move conversion constructor.
template <typename U,
typename = std::enable_if_t<std::is_convertible<U, T>::value>>
typename = std::enable_if_t<std::is_convertible_v<U, T>>>
ScopedJavaLocalRef(ScopedJavaLocalRef<U>&& other) : env_(other.env_) {
JavaRef<T>::steal(std::move(other));
}
Expand Down Expand Up @@ -235,15 +235,15 @@ class ScopedJavaLocalRef : public JavaRef<T> {

// Copy conversion assignment.
template <typename U,
typename = std::enable_if_t<std::is_convertible<U, T>::value>>
typename = std::enable_if_t<std::is_convertible_v<U, T>>>
ScopedJavaLocalRef& operator=(const ScopedJavaLocalRef<U>& other) {
Reset(other);
return *this;
}

// Move assignment.
template <typename U,
typename = std::enable_if_t<std::is_convertible<U, T>::value>>
typename = std::enable_if_t<std::is_convertible_v<U, T>>>
ScopedJavaLocalRef& operator=(ScopedJavaLocalRef<U>&& other) {
env_ = other.env_;
Reset();
Expand All @@ -260,7 +260,7 @@ class ScopedJavaLocalRef : public JavaRef<T> {
void Reset() { JavaRef<T>::ResetLocalRef(env_); }

template <typename U,
typename = std::enable_if_t<std::is_convertible<U, T>::value>>
typename = std::enable_if_t<std::is_convertible_v<U, T>>>
void Reset(const ScopedJavaLocalRef<U>& other) {
// We can copy over env_ here as |other| instance must be from the same
// thread as |this| local ref. (See class comment for multi-threading
Expand Down Expand Up @@ -316,7 +316,7 @@ class ScopedJavaGlobalRef : public JavaRef<T> {

// Copy conversion constructor.
template <typename U,
typename = std::enable_if_t<std::is_convertible<U, T>::value>>
typename = std::enable_if_t<std::is_convertible_v<U, T>>>
ScopedJavaGlobalRef(const ScopedJavaGlobalRef<U>& other) {
Reset(other);
}
Expand All @@ -329,7 +329,7 @@ class ScopedJavaGlobalRef : public JavaRef<T> {

// Move conversion constructor.
template <typename U,
typename = std::enable_if_t<std::is_convertible<U, T>::value>>
typename = std::enable_if_t<std::is_convertible_v<U, T>>>
ScopedJavaGlobalRef(ScopedJavaGlobalRef<U>&& other) {
JavaRef<T>::steal(std::move(other));
}
Expand Down Expand Up @@ -357,15 +357,15 @@ class ScopedJavaGlobalRef : public JavaRef<T> {

// Copy conversion assignment.
template <typename U,
typename = std::enable_if_t<std::is_convertible<U, T>::value>>
typename = std::enable_if_t<std::is_convertible_v<U, T>>>
ScopedJavaGlobalRef& operator=(const ScopedJavaGlobalRef<U>& other) {
Reset(other);
return *this;
}

// Move assignment.
template <typename U,
typename = std::enable_if_t<std::is_convertible<U, T>::value>>
typename = std::enable_if_t<std::is_convertible_v<U, T>>>
ScopedJavaGlobalRef& operator=(ScopedJavaGlobalRef<U>&& other) {
Reset();
JavaRef<T>::steal(std::move(other));
Expand All @@ -381,7 +381,7 @@ class ScopedJavaGlobalRef : public JavaRef<T> {
void Reset() { JavaRef<T>::ResetGlobalRef(); }

template <typename U,
typename = std::enable_if_t<std::is_convertible<U, T>::value>>
typename = std::enable_if_t<std::is_convertible_v<U, T>>>
void Reset(const ScopedJavaGlobalRef<U>& other) {
Reset(nullptr, other.obj());
}
Expand Down
6 changes: 3 additions & 3 deletions base/android/scoped_java_ref_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -284,18 +284,18 @@ TEST_F(JavaObjectArrayReaderTest, InputIteratorRequirements) {
JavaObjectArrayReader<jobject> reader(array_);
It i = reader.begin();

EXPECT_TRUE(std::is_copy_constructible<It>::value);
EXPECT_TRUE(std::is_copy_constructible_v<It>);
It copy = i;
EXPECT_EQ(copy, i);
EXPECT_EQ(It(i), i);

EXPECT_TRUE(std::is_copy_assignable<It>::value);
EXPECT_TRUE(std::is_copy_assignable_v<It>);
It assign = reader.end();
It& assign2 = (assign = i);
EXPECT_EQ(assign, i);
EXPECT_EQ(assign2, assign);

EXPECT_TRUE(std::is_destructible<It>::value);
EXPECT_TRUE(std::is_destructible_v<It>);

// Swappable
It left = reader.begin(), right = reader.end();
Expand Down
2 changes: 1 addition & 1 deletion base/apple/scoped_nsobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class scoped_nsobject : public scoped_nsprotocol<NST*> {
public:
using scoped_nsprotocol<NST*>::scoped_nsprotocol;

static_assert(std::is_same<NST, NSAutoreleasePool>::value == false,
static_assert(std::is_same_v<NST, NSAutoreleasePool> == false,
"Use @autoreleasepool instead");
};

Expand Down
2 changes: 1 addition & 1 deletion base/debug/crash_logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class BASE_EXPORT ScopedCrashKeyString {
::base::debug::CrashKeySize::Size1024)

#define SCOPED_CRASH_KEY_BOOL(category, name, data) \
static_assert(std::is_same<std::decay_t<decltype(data)>, bool>::value, \
static_assert(std::is_same_v<std::decay_t<decltype(data)>, bool>, \
"SCOPED_CRASH_KEY_BOOL must be passed a boolean value."); \
SCOPED_CRASH_KEY_STRING32(category, name, (data) ? "true" : "false")

Expand Down
2 changes: 1 addition & 1 deletion base/debug/crash_logging_unittest.nc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "base/debug/crash_logging.h"

#if defined(NCTEST_SCOPED_CRASH_KEY_BOOL_ON_NON_BOOL_ARG) // [r"static assertion failed due to requirement 'std::is_same<int, bool>::value': SCOPED_CRASH_KEY_BOOL must be passed a boolean value\."]
#if defined(NCTEST_SCOPED_CRASH_KEY_BOOL_ON_NON_BOOL_ARG) // [r"static assertion failed due to requirement 'std::is_same_v<int, bool>': SCOPED_CRASH_KEY_BOOL must be passed a boolean value\."]

void WontCompile() {
SCOPED_CRASH_KEY_BOOL(category, name, 1);
Expand Down
3 changes: 1 addition & 2 deletions base/debug/test_elf_image_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,7 @@ TestElfImage TestElfImageBuilder::Build() {
// static
template <typename T>
uint8_t* TestElfImageBuilder::AppendHdr(const T& hdr, uint8_t* loc) {
static_assert(std::is_trivially_copyable<T>::value,
"T should be a plain struct");
static_assert(std::is_trivially_copyable_v<T>, "T should be a plain struct");
memcpy(loc, &hdr, sizeof(T));
return loc + sizeof(T);
}
Expand Down
47 changes: 21 additions & 26 deletions base/functional/bind_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1598,56 +1598,51 @@ TEST_F(BindTest, OnceCallback) {
// Check if Callback variants have declarations of conversions as expected.
// Copy constructor and assignment of RepeatingCallback.
static_assert(
std::is_constructible<RepeatingClosure, const RepeatingClosure&>::value,
std::is_constructible_v<RepeatingClosure, const RepeatingClosure&>,
"RepeatingClosure should be copyable.");
static_assert(
std::is_assignable<RepeatingClosure, const RepeatingClosure&>::value,
"RepeatingClosure should be copy-assignable.");
static_assert(std::is_assignable_v<RepeatingClosure, const RepeatingClosure&>,
"RepeatingClosure should be copy-assignable.");

// Move constructor and assignment of RepeatingCallback.
static_assert(
std::is_constructible<RepeatingClosure, RepeatingClosure&&>::value,
"RepeatingClosure should be movable.");
static_assert(std::is_assignable<RepeatingClosure, RepeatingClosure&&>::value,
static_assert(std::is_constructible_v<RepeatingClosure, RepeatingClosure&&>,
"RepeatingClosure should be movable.");
static_assert(std::is_assignable_v<RepeatingClosure, RepeatingClosure&&>,
"RepeatingClosure should be move-assignable");

// Conversions from OnceCallback to RepeatingCallback.
static_assert(
!std::is_constructible<RepeatingClosure, const OnceClosure&>::value,
"OnceClosure should not be convertible to RepeatingClosure.");
static_assert(
!std::is_assignable<RepeatingClosure, const OnceClosure&>::value,
"OnceClosure should not be convertible to RepeatingClosure.");
static_assert(!std::is_constructible_v<RepeatingClosure, const OnceClosure&>,
"OnceClosure should not be convertible to RepeatingClosure.");
static_assert(!std::is_assignable_v<RepeatingClosure, const OnceClosure&>,
"OnceClosure should not be convertible to RepeatingClosure.");

// Destructive conversions from OnceCallback to RepeatingCallback.
static_assert(!std::is_constructible<RepeatingClosure, OnceClosure&&>::value,
static_assert(!std::is_constructible_v<RepeatingClosure, OnceClosure&&>,
"OnceClosure should not be convertible to RepeatingClosure.");
static_assert(!std::is_assignable<RepeatingClosure, OnceClosure&&>::value,
static_assert(!std::is_assignable_v<RepeatingClosure, OnceClosure&&>,
"OnceClosure should not be convertible to RepeatingClosure.");

// Copy constructor and assignment of OnceCallback.
static_assert(!std::is_constructible<OnceClosure, const OnceClosure&>::value,
static_assert(!std::is_constructible_v<OnceClosure, const OnceClosure&>,
"OnceClosure should not be copyable.");
static_assert(!std::is_assignable<OnceClosure, const OnceClosure&>::value,
static_assert(!std::is_assignable_v<OnceClosure, const OnceClosure&>,
"OnceClosure should not be copy-assignable");

// Move constructor and assignment of OnceCallback.
static_assert(std::is_constructible<OnceClosure, OnceClosure&&>::value,
static_assert(std::is_constructible_v<OnceClosure, OnceClosure&&>,
"OnceClosure should be movable.");
static_assert(std::is_assignable<OnceClosure, OnceClosure&&>::value,
static_assert(std::is_assignable_v<OnceClosure, OnceClosure&&>,
"OnceClosure should be move-assignable.");

// Conversions from RepeatingCallback to OnceCallback.
static_assert(
std::is_constructible<OnceClosure, const RepeatingClosure&>::value,
"RepeatingClosure should be convertible to OnceClosure.");
static_assert(std::is_assignable<OnceClosure, const RepeatingClosure&>::value,
static_assert(std::is_constructible_v<OnceClosure, const RepeatingClosure&>,
"RepeatingClosure should be convertible to OnceClosure.");
static_assert(std::is_assignable_v<OnceClosure, const RepeatingClosure&>,
"RepeatingClosure should be convertible to OnceClosure.");

// Destructive conversions from RepeatingCallback to OnceCallback.
static_assert(std::is_constructible<OnceClosure, RepeatingClosure&&>::value,
static_assert(std::is_constructible_v<OnceClosure, RepeatingClosure&&>,
"RepeatingClosure should be convertible to OnceClosure.");
static_assert(std::is_assignable<OnceClosure, RepeatingClosure&&>::value,
static_assert(std::is_assignable_v<OnceClosure, RepeatingClosure&&>,
"RepeatingClosure should be covretible to OnceClosure.");

OnceClosure cb = BindOnce(&VoidPolymorphic<>::Run);
Expand Down
54 changes: 25 additions & 29 deletions base/functional/callback_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,20 @@ class CallbackTest : public ::testing::Test {
};

TEST_F(CallbackTest, Types) {
static_assert(std::is_same<void, OnceClosure::ResultType>::value, "");
static_assert(std::is_same<void(), OnceClosure::RunType>::value, "");
static_assert(std::is_same_v<void, OnceClosure::ResultType>, "");
static_assert(std::is_same_v<void(), OnceClosure::RunType>, "");

using OnceCallbackT = OnceCallback<double(int, char)>;
static_assert(std::is_same<double, OnceCallbackT::ResultType>::value, "");
static_assert(std::is_same<double(int, char), OnceCallbackT::RunType>::value,
"");
static_assert(std::is_same_v<double, OnceCallbackT::ResultType>, "");
static_assert(std::is_same_v<double(int, char), OnceCallbackT::RunType>, "");

static_assert(std::is_same<void, RepeatingClosure::ResultType>::value, "");
static_assert(std::is_same<void(), RepeatingClosure::RunType>::value, "");
static_assert(std::is_same_v<void, RepeatingClosure::ResultType>, "");
static_assert(std::is_same_v<void(), RepeatingClosure::RunType>, "");

using RepeatingCallbackT = RepeatingCallback<bool(float, short)>;
static_assert(std::is_same<bool, RepeatingCallbackT::ResultType>::value, "");
static_assert(
std::is_same<bool(float, short), RepeatingCallbackT::RunType>::value, "");
static_assert(std::is_same_v<bool, RepeatingCallbackT::ResultType>, "");
static_assert(std::is_same_v<bool(float, short), RepeatingCallbackT::RunType>,
"");
}

// Ensure we can create unbound callbacks. We need this to be able to store
Expand Down Expand Up @@ -324,81 +323,78 @@ class CallbackThenTest<use_once, R(Args...), ThenR> {
return BindRepeating(function, std::forward<FArgs>(args)...);
}

template <typename R2 = R,
std::enable_if_t<!std::is_void<R2>::value, int> = 0>
template <typename R2 = R, std::enable_if_t<!std::is_void_v<R2>, int> = 0>
static int Outer(std::string* s,
std::unique_ptr<int> a,
std::unique_ptr<int> b) {
*s += "Outer";
*s += base::NumberToString(*a) + base::NumberToString(*b);
return *a + *b;
}
template <typename R2 = R,
std::enable_if_t<!std::is_void<R2>::value, int> = 0>
template <typename R2 = R, std::enable_if_t<!std::is_void_v<R2>, int> = 0>
static int Outer(std::string* s, int a, int b) {
*s += "Outer";
*s += base::NumberToString(a) + base::NumberToString(b);
return a + b;
}
template <typename R2 = R,
std::enable_if_t<!std::is_void<R2>::value, int> = 0>
template <typename R2 = R, std::enable_if_t<!std::is_void_v<R2>, int> = 0>
static int Outer(std::string* s) {
*s += "Outer";
*s += "None";
return 99;
}

template <typename R2 = R, std::enable_if_t<std::is_void<R2>::value, int> = 0>
template <typename R2 = R, std::enable_if_t<std::is_void_v<R2>, int> = 0>
static void Outer(std::string* s,
std::unique_ptr<int> a,
std::unique_ptr<int> b) {
*s += "Outer";
*s += base::NumberToString(*a) + base::NumberToString(*b);
}
template <typename R2 = R, std::enable_if_t<std::is_void<R2>::value, int> = 0>
template <typename R2 = R, std::enable_if_t<std::is_void_v<R2>, int> = 0>
static void Outer(std::string* s, int a, int b) {
*s += "Outer";
*s += base::NumberToString(a) + base::NumberToString(b);
}
template <typename R2 = R, std::enable_if_t<std::is_void<R2>::value, int> = 0>
template <typename R2 = R, std::enable_if_t<std::is_void_v<R2>, int> = 0>
static void Outer(std::string* s) {
*s += "Outer";
*s += "None";
}

template <typename OuterR,
typename InnerR,
std::enable_if_t<!std::is_void<OuterR>::value, int> = 0,
std::enable_if_t<!std::is_void<InnerR>::value, int> = 0>
std::enable_if_t<!std::is_void_v<OuterR>, int> = 0,
std::enable_if_t<!std::is_void_v<InnerR>, int> = 0>
static int Inner(std::string* s, OuterR a) {
static_assert(std::is_same<InnerR, int>::value, "Use int return type");
static_assert(std::is_same_v<InnerR, int>, "Use int return type");
*s += "Inner";
*s += base::NumberToString(a);
return a;
}
template <typename OuterR,
typename InnerR,
std::enable_if_t<std::is_void<OuterR>::value, int> = 0,
std::enable_if_t<!std::is_void<InnerR>::value, int> = 0>
std::enable_if_t<std::is_void_v<OuterR>, int> = 0,
std::enable_if_t<!std::is_void_v<InnerR>, int> = 0>
static int Inner(std::string* s) {
static_assert(std::is_same<InnerR, int>::value, "Use int return type");
static_assert(std::is_same_v<InnerR, int>, "Use int return type");
*s += "Inner";
*s += "None";
return 99;
}

template <typename OuterR,
typename InnerR,
std::enable_if_t<!std::is_void<OuterR>::value, int> = 0,
std::enable_if_t<std::is_void<InnerR>::value, int> = 0>
std::enable_if_t<!std::is_void_v<OuterR>, int> = 0,
std::enable_if_t<std::is_void_v<InnerR>, int> = 0>
static void Inner(std::string* s, OuterR a) {
*s += "Inner";
*s += base::NumberToString(a);
}
template <typename OuterR,
typename InnerR,
std::enable_if_t<std::is_void<OuterR>::value, int> = 0,
std::enable_if_t<std::is_void<InnerR>::value, int> = 0>
std::enable_if_t<std::is_void_v<OuterR>, int> = 0,
std::enable_if_t<std::is_void_v<InnerR>, int> = 0>
static void Inner(std::string* s) {
*s += "Inner";
*s += "None";
Expand Down
8 changes: 3 additions & 5 deletions base/functional/invoke.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,15 @@ struct is_reference_wrapper<std::reference_wrapper<T>> : std::true_type {};

// Small helpers used below in internal::invoke to make the SFINAE more concise.
template <typename F>
const bool& IsMemFunPtr =
std::is_member_function_pointer<std::decay_t<F>>::value;
const bool& IsMemFunPtr = std::is_member_function_pointer_v<std::decay_t<F>>;

template <typename F>
const bool& IsMemObjPtr = std::is_member_object_pointer<std::decay_t<F>>::value;
const bool& IsMemObjPtr = std::is_member_object_pointer_v<std::decay_t<F>>;

template <typename F,
typename T,
typename MemPtrClass = member_pointer_class_t<std::decay_t<F>>>
const bool& IsMemPtrToBaseOf =
std::is_base_of<MemPtrClass, std::decay_t<T>>::value;
const bool& IsMemPtrToBaseOf = std::is_base_of_v<MemPtrClass, std::decay_t<T>>;

template <typename T>
const bool& IsRefWrapper = is_reference_wrapper<std::decay_t<T>>::value;
Expand Down
2 changes: 1 addition & 1 deletion base/memory/raw_scoped_refptr_mismatch_checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct NeedsScopedRefptrButGetsRawPtr
IsRefCountedType<base::RemoveRawRefT<T>>>,
std::conjunction<base::IsPointer<T>,
IsRefCountedType<base::RemovePointerT<T>>>> {
static_assert(!std::is_reference<T>::value,
static_assert(!std::is_reference_v<T>,
"NeedsScopedRefptrButGetsRawPtr requires non-reference type.");
};

Expand Down

0 comments on commit b42fe75

Please sign in to comment.