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 4/x:
  * ./
  * trace_event/
  * types/

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: I4bc6bb5cfc9cc942ec21b10abeadd55c262f7cd5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4942361
Commit-Queue: Andrew Rayskiy <greengrape@google.com>
Reviewed-by: Francois Pierre Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1211811}
  • Loading branch information
Andrew Rayskiy authored and Chromium LUCI CQ committed Oct 18, 2023
1 parent cd191d8 commit 6299123
Show file tree
Hide file tree
Showing 26 changed files with 153 additions and 173 deletions.
2 changes: 1 addition & 1 deletion base/atomicops_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ static void TestStore() {

AtomicType value;

if constexpr (std::is_same<AtomicType, base::subtle::Atomic32>::value) {
if constexpr (std::is_same_v<AtomicType, base::subtle::Atomic32>) {
base::subtle::NoBarrier_Store(&value, kVal1);
EXPECT_EQ(kVal1, value);
base::subtle::NoBarrier_Store(&value, kVal2);
Expand Down
4 changes: 2 additions & 2 deletions base/big_endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ inline uint8_t ByteSwapIfLittleEndian(uint8_t val) {
// This would cause SIGBUS on ARMv5 or earlier and ARMv6-M.
template <typename T>
inline void ReadBigEndian(const uint8_t buf[], T* out) {
static_assert(std::is_integral<T>::value, "T has to be an integral type.");
static_assert(std::is_integral_v<T>, "T has to be an integral type.");
// Make an unsigned version of the output type to make shift possible
// without UB.
typename std::make_unsigned<T>::type raw;
Expand All @@ -71,7 +71,7 @@ inline void ReadBigEndian(const uint8_t buf[], T* out) {
// Note: this loop is unrolled with -O1 and above.
template<typename T>
inline void WriteBigEndian(char buf[], T val) {
static_assert(std::is_integral<T>::value, "T has to be an integral type.");
static_assert(std::is_integral_v<T>, "T has to be an integral type.");
const auto unsigned_val =
static_cast<typename std::make_unsigned<T>::type>(val);
const auto raw = internal::ByteSwapIfLittleEndian(unsigned_val);
Expand Down
10 changes: 4 additions & 6 deletions base/bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace bits {
// Returns true iff |value| is a power of 2.
//
// TODO(pkasting): When C++20 is available, replace with std::has_single_bit().
template <typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
constexpr bool IsPowerOfTwo(T value) {
// From "Hacker's Delight": Section 2.1 Manipulating Rightmost Bits.
//
Expand Down Expand Up @@ -85,8 +85,7 @@ inline T* AlignUp(T* ptr, uintptr_t alignment) {
// do better, but we'll avoid doing that unless we see proof that we need to.
template <typename T, int bits = sizeof(T) * 8>
ALWAYS_INLINE constexpr
typename std::enable_if<std::is_unsigned<T>::value && sizeof(T) <= 8,
int>::type
typename std::enable_if<std::is_unsigned_v<T> && sizeof(T) <= 8, int>::type
CountLeadingZeroBits(T value) {
static_assert(bits > 0, "invalid instantiation");
return LIKELY(value)
Expand All @@ -98,8 +97,7 @@ ALWAYS_INLINE constexpr

template <typename T, int bits = sizeof(T) * 8>
ALWAYS_INLINE constexpr
typename std::enable_if<std::is_unsigned<T>::value && sizeof(T) <= 8,
int>::type
typename std::enable_if<std::is_unsigned_v<T> && sizeof(T) <= 8, int>::type
CountTrailingZeroBits(T value) {
return LIKELY(value) ? bits == 64
? __builtin_ctzll(static_cast<uint64_t>(value))
Expand Down Expand Up @@ -130,7 +128,7 @@ constexpr int Log2Ceiling(uint32_t n) {
// Can be used instead of manually shifting a 1 to the left.
template <typename T>
constexpr T LeftmostBit() {
static_assert(std::is_integral<T>::value,
static_assert(std::is_integral_v<T>,
"This function can only be used with integral types.");
T one(1u);
return one << (8 * sizeof(T) - 1);
Expand Down
49 changes: 24 additions & 25 deletions base/check_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ BASE_EXPORT char* StreamValToStr(const void* v,
template <typename T>
inline typename std::enable_if<
base::internal::SupportsOstreamOperator<const T&> &&
!std::is_function<typename std::remove_pointer<T>::type>::value,
!std::is_function_v<typename std::remove_pointer<T>::type>,
char*>::type
CheckOpValueStr(const T& v) {
auto f = [](std::ostream& s, const void* p) {
Expand Down Expand Up @@ -111,7 +111,7 @@ CheckOpValueStr(const T& v) {
// pointers, so this is a no-op for MSVC.)
template <typename T>
inline typename std::enable_if<
std::is_function<typename std::remove_pointer<T>::type>::value,
std::is_function_v<typename std::remove_pointer<T>::type>,
char*>::type
CheckOpValueStr(const T& v) {
return CheckOpValueStr(reinterpret_cast<const void*>(v));
Expand All @@ -121,8 +121,7 @@ CheckOpValueStr(const T& v) {
// (i.e. scoped enums where no operator<< overload was declared).
template <typename T>
inline typename std::enable_if<
!base::internal::SupportsOstreamOperator<const T&> &&
std::is_enum<T>::value,
!base::internal::SupportsOstreamOperator<const T&> && std::is_enum_v<T>,
char*>::type
CheckOpValueStr(const T& v) {
return CheckOpValueStr(
Expand Down Expand Up @@ -169,27 +168,27 @@ BASE_EXPORT char* CreateCheckOpLogMessageString(const char* expr_str,

// The second overload avoids address-taking of static members for
// fundamental types.
#define DEFINE_CHECK_OP_IMPL(name, op) \
template <typename T, typename U, \
std::enable_if_t<!std::is_fundamental<T>::value || \
!std::is_fundamental<U>::value, \
int> = 0> \
constexpr char* Check##name##Impl(const T& v1, const U& v2, \
const char* expr_str) { \
if (LIKELY(ANALYZER_ASSUME_TRUE(v1 op v2))) \
return nullptr; \
return CreateCheckOpLogMessageString(expr_str, CheckOpValueStr(v1), \
CheckOpValueStr(v2)); \
} \
template <typename T, typename U, \
std::enable_if_t<std::is_fundamental<T>::value && \
std::is_fundamental<U>::value, \
int> = 0> \
constexpr char* Check##name##Impl(T v1, U v2, const char* expr_str) { \
if (LIKELY(ANALYZER_ASSUME_TRUE(v1 op v2))) \
return nullptr; \
return CreateCheckOpLogMessageString(expr_str, CheckOpValueStr(v1), \
CheckOpValueStr(v2)); \
#define DEFINE_CHECK_OP_IMPL(name, op) \
template < \
typename T, typename U, \
std::enable_if_t<!std::is_fundamental_v<T> || !std::is_fundamental_v<U>, \
int> = 0> \
constexpr char* Check##name##Impl(const T& v1, const U& v2, \
const char* expr_str) { \
if (LIKELY(ANALYZER_ASSUME_TRUE(v1 op v2))) \
return nullptr; \
return CreateCheckOpLogMessageString(expr_str, CheckOpValueStr(v1), \
CheckOpValueStr(v2)); \
} \
template < \
typename T, typename U, \
std::enable_if_t<std::is_fundamental_v<T> && std::is_fundamental_v<U>, \
int> = 0> \
constexpr char* Check##name##Impl(T v1, U v2, const char* expr_str) { \
if (LIKELY(ANALYZER_ASSUME_TRUE(v1 op v2))) \
return nullptr; \
return CreateCheckOpLogMessageString(expr_str, CheckOpValueStr(v1), \
CheckOpValueStr(v2)); \
}

// clang-format off
Expand Down
2 changes: 1 addition & 1 deletion base/cxx20_to_address.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct has_std_to_address<
// Reference: https://wg21.link/pointer.conversion#lib:to_address
template <typename T>
constexpr T* to_address(T* p) noexcept {
static_assert(!std::is_function<T>::value,
static_assert(!std::is_function_v<T>,
"Error: T must not be a function type.");
return p;
}
Expand Down
5 changes: 2 additions & 3 deletions base/moving_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -699,9 +699,8 @@ class MovingWindow {
typename std::conditional<
internal::has_member_mean<EnabledFeatures>::value ||
internal::has_memeber_deviation<EnabledFeatures>::value,
internal::MovingMeanBase<T,
MeanSumType,
std::is_floating_point<MeanSumType>::value>,
internal::
MovingMeanBase<T, MeanSumType, std::is_floating_point_v<MeanSumType>>,
internal::NullMeanImpl<T>>::type mean_impl_;

// Member for calculating deviation.
Expand Down
4 changes: 2 additions & 2 deletions base/observer_list_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class BASE_EXPORT UncheckedObserverAdapter {
template <class ObserverType>
static ObserverType* Get(const UncheckedObserverAdapter& adapter) {
static_assert(
!std::is_base_of<CheckedObserver, ObserverType>::value,
!std::is_base_of_v<CheckedObserver, ObserverType>,
"CheckedObserver classes must not use ObserverList<T>::Unchecked.");
return static_cast<ObserverType*>(adapter.ptr_);
}
Expand Down Expand Up @@ -102,7 +102,7 @@ class BASE_EXPORT CheckedObserverAdapter {
template <class ObserverType>
static ObserverType* Get(const CheckedObserverAdapter& adapter) {
static_assert(
std::is_base_of<CheckedObserver, ObserverType>::value,
std::is_base_of_v<CheckedObserver, ObserverType>,
"Observers should inherit from base::CheckedObserver. "
"Use ObserverList<T>::Unchecked to observe with raw pointers.");
DCHECK(adapter.weak_ptr_);
Expand Down
4 changes: 2 additions & 2 deletions base/observer_list_unittest.nc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace base {

#if defined(NCTEST_CHECKED_OBSERVER_USING_UNCHECKED_LIST) // [r"fatal error: static assertion failed due to requirement '!std::is_base_of<base::CheckedObserver, Observer>::value': CheckedObserver classes must not use ObserverList<T>::Unchecked."]
#if defined(NCTEST_CHECKED_OBSERVER_USING_UNCHECKED_LIST) // [r"fatal error: static assertion failed due to requirement '!std::is_base_of_v<base::CheckedObserver, Observer>': CheckedObserver classes must not use ObserverList<T>::Unchecked."]

void WontCompile() {
struct Observer : public CheckedObserver {
Expand All @@ -22,7 +22,7 @@ void WontCompile() {
observer.OnObserve();
}

#elif defined(NCTEST_UNCHECKED_OBSERVER_USING_CHECKED_LIST) // [r"fatal error: static assertion failed due to requirement 'std::is_base_of<base::CheckedObserver, UncheckedObserver>::value': Observers should inherit from base::CheckedObserver. Use ObserverList<T>::Unchecked to observe with raw pointers."]
#elif defined(NCTEST_UNCHECKED_OBSERVER_USING_CHECKED_LIST) // [r"fatal error: static assertion failed due to requirement 'std::is_base_of_v<base::CheckedObserver, UncheckedObserver>': Observers should inherit from base::CheckedObserver. Use ObserverList<T>::Unchecked to observe with raw pointers."]

void WontCompile() {
struct UncheckedObserver {
Expand Down
12 changes: 5 additions & 7 deletions base/parameter_pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,23 @@ template <typename... Ts>
struct ParameterPack {
// Checks if |Type| occurs in the parameter pack.
template <typename Type>
using HasType =
std::bool_constant<any_of({std::is_same<Type, Ts>::value...})>;
using HasType = std::bool_constant<any_of({std::is_same_v<Type, Ts>...})>;

// Checks if the parameter pack only contains |Type|.
template <typename Type>
using OnlyHasType =
std::bool_constant<all_of({std::is_same<Type, Ts>::value...})>;
using OnlyHasType = std::bool_constant<all_of({std::is_same_v<Type, Ts>...})>;

// Checks if |Type| occurs only once in the parameter pack.
template <typename Type>
using IsUniqueInPack =
std::bool_constant<count({std::is_same<Type, Ts>::value...}, true) == 1>;
std::bool_constant<count({std::is_same_v<Type, Ts>...}, true) == 1>;

// Returns the zero-based index of |Type| within |Pack...| or |pack_npos| if
// it's not within the pack.
template <typename Type>
static constexpr size_t IndexInPack() {
size_t index = 0;
for (bool value : {std::is_same<Type, Ts>::value...}) {
for (bool value : {std::is_same_v<Type, Ts>...}) {
if (value)
return index;
index++;
Expand All @@ -74,7 +72,7 @@ struct ParameterPack {

// Checks if every type in the parameter pack is the same.
using IsAllSameType =
std::bool_constant<all_of({std::is_same<NthType<0>, Ts>::value...})>;
std::bool_constant<all_of({std::is_same_v<NthType<0>, Ts>...})>;
};

} // namespace base
Expand Down
9 changes: 3 additions & 6 deletions base/parameter_pack_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,11 @@ TEST(ParameterPack, IndexInPack) {

TEST(ParameterPack, NthType) {
static_assert(
std::is_same<int, ParameterPack<int, float, bool>::NthType<0>>::value,
"");
std::is_same_v<int, ParameterPack<int, float, bool>::NthType<0>>, "");
static_assert(
std::is_same<float, ParameterPack<int, float, bool>::NthType<1>>::value,
"");
std::is_same_v<float, ParameterPack<int, float, bool>::NthType<1>>, "");
static_assert(
std::is_same<bool, ParameterPack<int, float, bool>::NthType<2>>::value,
"");
std::is_same_v<bool, ParameterPack<int, float, bool>::NthType<2>>, "");
}

TEST(ParameterPack, IsAllSameType) {
Expand Down
15 changes: 7 additions & 8 deletions base/safe_numerics_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ static_assert(BigEnoughPromotion<int32_t, uint32_t>::is_contained, "");
static_assert(BigEnoughPromotion<intmax_t, int8_t>::is_contained, "");
static_assert(!BigEnoughPromotion<uintmax_t, int8_t>::is_contained, "");
static_assert(
std::is_same<BigEnoughPromotion<int16_t, int8_t>::type, int16_t>::value,
std::is_same_v<BigEnoughPromotion<int16_t, int8_t>::type, int16_t>,
"");
static_assert(
std::is_same<BigEnoughPromotion<int32_t, uint32_t>::type, int64_t>::value,
std::is_same_v<BigEnoughPromotion<int32_t, uint32_t>::type, int64_t>,
"");
static_assert(
std::is_same<BigEnoughPromotion<intmax_t, int8_t>::type, intmax_t>::value,
std::is_same_v<BigEnoughPromotion<intmax_t, int8_t>::type, intmax_t>,
"");
static_assert(
std::is_same<BigEnoughPromotion<uintmax_t, int8_t>::type, uintmax_t>::value,
std::is_same_v<BigEnoughPromotion<uintmax_t, int8_t>::type, uintmax_t>,
"");
static_assert(BigEnoughPromotion<int16_t, int8_t>::is_contained, "");
static_assert(BigEnoughPromotion<int32_t, uint32_t>::is_contained, "");
Expand Down Expand Up @@ -1082,7 +1082,7 @@ struct TestNumericConversion<Dst, Src, SIGN_PRESERVING_VALUE_PRESERVING> {
} else if (numeric_limits<Src>::is_signed) {
// This block reverses the Src to Dst relationship so we don't have to
// complicate the test macros.
if (!std::is_same<Src, Dst>::value) {
if (!std::is_same_v<Src, Dst>) {
TEST_EXPECTED_SUCCESS(CheckDiv(SrcLimits::lowest(), Dst(-1)));
}
TEST_EXPECTED_RANGE(RANGE_VALID, static_cast<Src>(-1));
Expand Down Expand Up @@ -1419,9 +1419,8 @@ size_t TestOverload(size_t) { // Overload succeeds.
return 0;
}

static_assert(
std::is_same<decltype(TestOverload(StrictNumeric<int>())), int>::value,
"");
static_assert(std::is_same_v<decltype(TestOverload(StrictNumeric<int>())), int>,
"");
static_assert(std::is_same<decltype(TestOverload(StrictNumeric<size_t>())),
size_t>::value,
"");
Expand Down
8 changes: 4 additions & 4 deletions base/scoped_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class ScopedGeneric {

template <typename Void = void>
typename std::enable_if_t<
std::is_base_of<ScopedGenericOwnershipTracking, Traits>::value,
std::is_base_of_v<ScopedGenericOwnershipTracking, Traits>,
Void>
TrackAcquire(const T& value) {
if (value != traits_type::InvalidValue()) {
Expand All @@ -272,13 +272,13 @@ class ScopedGeneric {

template <typename Void = void>
typename std::enable_if_t<
!std::is_base_of<ScopedGenericOwnershipTracking, Traits>::value,
!std::is_base_of_v<ScopedGenericOwnershipTracking, Traits>,
Void>
TrackAcquire(const T& value) {}

template <typename Void = void>
typename std::enable_if_t<
std::is_base_of<ScopedGenericOwnershipTracking, Traits>::value,
std::is_base_of_v<ScopedGenericOwnershipTracking, Traits>,
Void>
TrackRelease(const T& value) {
if (value != traits_type::InvalidValue()) {
Expand All @@ -288,7 +288,7 @@ class ScopedGeneric {

template <typename Void = void>
typename std::enable_if_t<
!std::is_base_of<ScopedGenericOwnershipTracking, Traits>::value,
!std::is_base_of_v<ScopedGenericOwnershipTracking, Traits>,
Void>
TrackRelease(const T& value) {}

Expand Down
4 changes: 2 additions & 2 deletions base/template_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ namespace internal {

// The indirection with std::is_enum<T> is required, because instantiating
// std::underlying_type_t<T> when T is not an enum is UB prior to C++20.
template <typename T, bool = std::is_enum<T>::value>
template <typename T, bool = std::is_enum_v<T>>
struct IsScopedEnumImpl : std::false_type {};

template <typename T>
struct IsScopedEnumImpl<T, /*std::is_enum<T>::value=*/true>
struct IsScopedEnumImpl<T, /*std::is_enum_v<T>=*/true>
: std::negation<std::is_convertible<T, std::underlying_type_t<T>>> {};

} // namespace internal
Expand Down
32 changes: 14 additions & 18 deletions base/template_util_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,26 @@ TEST(TemplateUtil, IsScopedEnum) {
}

TEST(TemplateUtil, RemoveCvRefT) {
static_assert(std::is_same<int, remove_cvref_t<const int>>::value, "");
static_assert(std::is_same<int, remove_cvref_t<const volatile int>>::value,
"");
static_assert(std::is_same<int, remove_cvref_t<int&>>::value, "");
static_assert(std::is_same<int, remove_cvref_t<const int&>>::value, "");
static_assert(std::is_same<int, remove_cvref_t<const volatile int&>>::value,
"");
static_assert(std::is_same<int, remove_cvref_t<int&&>>::value, "");
static_assert(std::is_same_v<int, remove_cvref_t<const int>>, "");
static_assert(std::is_same_v<int, remove_cvref_t<const volatile int>>, "");
static_assert(std::is_same_v<int, remove_cvref_t<int&>>, "");
static_assert(std::is_same_v<int, remove_cvref_t<const int&>>, "");
static_assert(std::is_same_v<int, remove_cvref_t<const volatile int&>>, "");
static_assert(std::is_same_v<int, remove_cvref_t<int&&>>, "");
static_assert(
std::is_same<SimpleStruct, remove_cvref_t<const SimpleStruct&>>::value,
"");
static_assert(std::is_same<int*, remove_cvref_t<int*>>::value, "");
std::is_same_v<SimpleStruct, remove_cvref_t<const SimpleStruct&>>, "");
static_assert(std::is_same_v<int*, remove_cvref_t<int*>>, "");

// Test references and pointers to arrays.
static_assert(std::is_same<int[3], remove_cvref_t<int[3]>>::value, "");
static_assert(std::is_same<int[3], remove_cvref_t<int(&)[3]>>::value, "");
static_assert(std::is_same<int(*)[3], remove_cvref_t<int(*)[3]>>::value, "");
static_assert(std::is_same_v<int[3], remove_cvref_t<int[3]>>, "");
static_assert(std::is_same_v<int[3], remove_cvref_t<int(&)[3]>>, "");
static_assert(std::is_same_v<int(*)[3], remove_cvref_t<int(*)[3]>>, "");

// Test references and pointers to functions.
static_assert(std::is_same<void(int), remove_cvref_t<void(int)>>::value, "");
static_assert(std::is_same<void(int), remove_cvref_t<void (&)(int)>>::value,
static_assert(std::is_same_v<void(int), remove_cvref_t<void(int)>>, "");
static_assert(std::is_same_v<void(int), remove_cvref_t<void (&)(int)>>, "");
static_assert(std::is_same_v<void (*)(int), remove_cvref_t<void (*)(int)>>,
"");
static_assert(
std::is_same<void (*)(int), remove_cvref_t<void (*)(int)>>::value, "");
}

} // namespace
Expand Down
2 changes: 1 addition & 1 deletion base/trace_event/category_registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace trace_event {
namespace {

// |categories_| might end up causing creating dynamic initializers if not POD.
static_assert(std::is_pod<TraceCategory>::value, "TraceCategory must be POD");
static_assert(std::is_pod_v<TraceCategory>, "TraceCategory must be POD");

} // namespace

Expand Down

0 comments on commit 6299123

Please sign in to comment.