Skip to content

Commit 4299423

Browse files
r-barnespytorchmergebot
authored andcommitted
std::value/std::type -> std::_v/std::_t (pytorch#138746)
Pull Request resolved: pytorch#138746 Approved by: https://github.com/cyyever, https://github.com/malfet
1 parent fb36daa commit 4299423

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+233
-238
lines changed

aten/src/ATen/core/Dict.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class DictEntryRef final {
8080

8181
template<class Value_>
8282
void setValue(Value_&& value) const {
83-
static_assert(std::is_constructible<Value, Value_>::value, "Wrong type for the value argument of setValue()");
83+
static_assert(std::is_constructible_v<Value, Value_>, "Wrong type for the value argument of setValue()");
8484
iterator_->second = Value(std::forward<Value_>(value));
8585
}
8686

aten/src/ATen/core/Dict_inl.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,17 @@ Dict<Key, Value>::Dict()
6969
:Dict(make_intrusive<detail::DictImpl>(
7070
detail::DictImpl::dict_map_type(),
7171
detail::DictImpl::DictElementTypes{getTypePtr<Key>(), getTypePtr<Value>()})) {
72-
static_assert(!std::is_same<Key, IValue>::value, "This constructor is not valid for Dict<IValue, _>. Please use c10::impl::GenericDict(keyType, valueType) instead.");
73-
static_assert(!std::is_same<Value, IValue>::value, "This constructor is not valid for Dict<_, IValue>. Please use c10::impl::GenericDict(keyType, valueType) instead.");
72+
static_assert(!std::is_same_v<Key, IValue>, "This constructor is not valid for Dict<IValue, _>. Please use c10::impl::GenericDict(keyType, valueType) instead.");
73+
static_assert(!std::is_same_v<Value, IValue>, "This constructor is not valid for Dict<_, IValue>. Please use c10::impl::GenericDict(keyType, valueType) instead.");
7474
}
7575

7676
template<class Key, class Value>
7777
Dict<Key, Value>::Dict(TypePtr keyType, TypePtr valueType)
7878
: Dict(make_intrusive<detail::DictImpl>(
7979
detail::DictImpl::dict_map_type(),
8080
detail::DictImpl::DictElementTypes {std::move(keyType), std::move(valueType)})) {
81-
static_assert(std::is_same<Key, IValue>::value, "This constructor is only valid for c10::impl::GenericDict.");
82-
static_assert(std::is_same<Value, IValue>::value, "This constructor is only valid for c10::impl::GenericDict.");
81+
static_assert(std::is_same_v<Key, IValue>, "This constructor is only valid for c10::impl::GenericDict.");
82+
static_assert(std::is_same_v<Value, IValue>, "This constructor is only valid for c10::impl::GenericDict.");
8383
}
8484

8585
template<class Key, class Value>
@@ -118,8 +118,8 @@ void Dict<Key, Value>::clear() const {
118118
template<class Key, class Value>
119119
template<class Key_, class Value_>
120120
std::pair<typename Dict<Key, Value>::iterator, bool> Dict<Key, Value>::insert(Key_&& key, Value_&& value) const {
121-
static_assert(std::is_constructible<Key, Key_>::value, "Wrong type for the key argument of Dict::insert");
122-
static_assert(std::is_constructible<Value, Value_>::value, "Wrong type for the value argument of Dict::insert");
121+
static_assert(std::is_constructible_v<Key, Key_>, "Wrong type for the key argument of Dict::insert");
122+
static_assert(std::is_constructible_v<Value, Value_>, "Wrong type for the value argument of Dict::insert");
123123
auto inserted = impl_->dict.emplace(
124124
Key(std::forward<Key_>(key)),
125125
Value(std::forward<Value_>(value)));
@@ -129,8 +129,8 @@ std::pair<typename Dict<Key, Value>::iterator, bool> Dict<Key, Value>::insert(Ke
129129
template<class Key, class Value>
130130
template<class Key_, class Value_>
131131
std::pair<typename Dict<Key, Value>::iterator, bool> Dict<Key, Value>::insert_or_assign(Key_&& key, Value_&& value) const {
132-
static_assert(std::is_constructible<Key, Key_>::value, "Wrong type for the key argument of Dict::insert_or_assign");
133-
static_assert(std::is_constructible<Value, Value_>::value, "Wrong type for the value argument of Dict::insert_or_assign");
132+
static_assert(std::is_constructible_v<Key, Key_>, "Wrong type for the key argument of Dict::insert_or_assign");
133+
static_assert(std::is_constructible_v<Value, Value_>, "Wrong type for the value argument of Dict::insert_or_assign");
134134
auto inserted = impl_->dict.insert_or_assign(
135135
Key(std::forward<Key_>(key)),
136136
Value(std::forward<Value_>(value)));

aten/src/ATen/core/DistributionsHelper.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ struct uniform_int_from_to_distribution {
4242
template <typename RNG>
4343
C10_HOST_DEVICE inline T operator()(RNG generator) {
4444
if ((
45-
std::is_same<T, int64_t>::value ||
46-
std::is_same<T, double>::value ||
47-
std::is_same<T, float>::value ||
48-
std::is_same<T, at::BFloat16>::value) && range_ >= 1ULL << 32)
45+
std::is_same_v<T, int64_t> ||
46+
std::is_same_v<T, double> ||
47+
std::is_same_v<T, float> ||
48+
std::is_same_v<T, at::BFloat16>) && range_ >= 1ULL << 32)
4949
{
5050
return transformation::uniform_int_from_to<T>(generator->random64(), range_, base_);
5151
} else {

aten/src/ATen/core/List_inl.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ List<T>::List()
2121
: List(make_intrusive<c10::detail::ListImpl>(
2222
typename c10::detail::ListImpl::list_type(),
2323
getTypePtr<T>())) {
24-
static_assert(!std::is_same<T, IValue>::value, "This constructor is not valid for List<IValue>. Please use c10::impl::GenericList(elementType) instead.");
24+
static_assert(!std::is_same_v<T, IValue>, "This constructor is not valid for List<IValue>. Please use c10::impl::GenericList(elementType) instead.");
2525
}
2626

2727
template<class T>
2828
List<T>::List(ArrayRef<T> values)
2929
: List(make_intrusive<c10::detail::ListImpl>(
3030
typename c10::detail::ListImpl::list_type(),
3131
getTypePtr<T>())) {
32-
static_assert(!std::is_same<T, IValue>::value, "This constructor is not valid for List<IValue>. Please use c10::impl::GenericList(elementType).");
32+
static_assert(!std::is_same_v<T, IValue>, "This constructor is not valid for List<IValue>. Please use c10::impl::GenericList(elementType).");
3333
impl_->list.reserve(values.size());
3434
for (const T& element : values) {
3535
impl_->list.push_back(element);
@@ -39,15 +39,15 @@ List<T>::List(ArrayRef<T> values)
3939
template<class T>
4040
List<T>::List(std::initializer_list<T> initial_values)
4141
: List(ArrayRef<T>(initial_values)) {
42-
static_assert(!std::is_same<T, IValue>::value, "This constructor is not valid for List<IValue>. Please use c10::impl::GenericList(elementType).");
42+
static_assert(!std::is_same_v<T, IValue>, "This constructor is not valid for List<IValue>. Please use c10::impl::GenericList(elementType).");
4343
}
4444

4545
template<class T>
4646
List<T>::List(TypePtr elementType)
4747
: List(make_intrusive<c10::detail::ListImpl>(
4848
typename c10::detail::ListImpl::list_type(),
4949
std::move(elementType))) {
50-
static_assert(std::is_same<T, IValue>::value || std::is_same<T, c10::intrusive_ptr<ivalue::Future>>::value,
50+
static_assert(std::is_same_v<T, IValue> || std::is_same<T, c10::intrusive_ptr<ivalue::Future>>::value,
5151
"This constructor is only valid for c10::impl::GenericList or List<Future>.");
5252
}
5353

aten/src/ATen/core/Tensor.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ template <typename T>
7272
auto Tensor::register_hook(T&& hook) const -> Tensor::hook_return_void_t<T> {
7373
// Return the grad argument in case of a hook with void return type to have an
7474
// std::function with Tensor return type
75-
static_assert(std::is_same<decltype(hook(Tensor())), void>::value,
75+
static_assert(std::is_same_v<decltype(hook(Tensor())), void>,
7676
"Expected hook to return void");
7777
return _register_hook([fn=std::forward<T>(hook)](const TensorBase& grad_base) {
7878
TensorRef grad(grad_base);

aten/src/ATen/core/blob.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class TORCH_API Blob final : public c10::intrusive_ptr_target {
9595
template <class T>
9696
T* GetMutable() {
9797
static_assert(
98-
std::is_default_constructible<T>::value,
98+
std::is_default_constructible_v<T>,
9999
"GetMutable can't be called with non-default-constructible types. "
100100
"Try using specialized methods");
101101
if (IsType<T>()) {

aten/src/ATen/core/boxing/BoxedKernel_impl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ inline BoxedKernel BoxedKernel::makeNamedNotSupported() {
8080

8181
template<class KernelFunctor>
8282
inline BoxedKernel BoxedKernel::makeFromFunctor(std::unique_ptr<KernelFunctor> kernelFunctor) {
83-
static_assert(std::is_base_of<OperatorKernel, KernelFunctor>::value, "Tried to call BoxedKernel::makeFromFunctor<KernelFunctor>, but the functor doesn't inherit from c10::OperatorKernel. Please have the functor inherit from it.");
83+
static_assert(std::is_base_of_v<OperatorKernel, KernelFunctor>, "Tried to call BoxedKernel::makeFromFunctor<KernelFunctor>, but the functor doesn't inherit from c10::OperatorKernel. Please have the functor inherit from it.");
8484
return BoxedKernel(
8585
std::move(kernelFunctor),
8686
[](OperatorKernel* kernel, const OperatorHandle& op, DispatchKeySet ks, Stack* stack) {

aten/src/ATen/core/boxing/KernelFunction_impl.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ inline KernelFunction KernelFunction::makeFromUnboxedFunctor(std::unique_ptr<Ope
162162
// This assertion is costly for build time so it's debug-gated.
163163
static_assert(guts::is_functor<KernelFunctor>::value, "Tried to call KernelFunction::makeFromUnboxedFunctor<KernelFunctor> but the argument is not a functor.");
164164
#endif
165-
static_assert(std::is_base_of<OperatorKernel, KernelFunctor>::value, "Tried to call KernelFunction::makeFromUnboxedFunctor<KernelFunctor>, but the functor doesn't inherit from c10::OperatorKernel. Please have the functor inherit from it.");
165+
static_assert(std::is_base_of_v<OperatorKernel, KernelFunctor>, "Tried to call KernelFunction::makeFromUnboxedFunctor<KernelFunctor>, but the functor doesn't inherit from c10::OperatorKernel. Please have the functor inherit from it.");
166166

167167
auto* unboxed_fn = &impl::wrap_kernel_functor_unboxed<KernelFunctor>::call;
168168
void* void_unboxed_fn = reinterpret_cast<void*>(unboxed_fn);
@@ -184,7 +184,7 @@ inline KernelFunction KernelFunction::makeFromBoxedFunctor(std::unique_ptr<Kerne
184184
template<class FuncPtr, bool AllowLegacyTypes>
185185
inline KernelFunction KernelFunction::makeFromUnboxedFunction(FuncPtr func_ptr) {
186186
static_assert(is_compile_time_function_pointer<FuncPtr>::value, "Tried to call KernelFunction::makeFromUnboxedFunction with an invalid parameter. It must be a function pointer created with TORCH_FN.");
187-
static_assert(!std::is_same<typename FuncPtr::FuncType, BoxedKernelFunction>::value, "Tried to call KernelFunction::makeFromUnboxedFunction with a boxed function pointer. Please use KernelFunction::makeFromBoxedFunction instead.");
187+
static_assert(!std::is_same_v<typename FuncPtr::FuncType, BoxedKernelFunction>, "Tried to call KernelFunction::makeFromUnboxedFunction with a boxed function pointer. Please use KernelFunction::makeFromBoxedFunction instead.");
188188
#if defined(__GNUC__) && defined(__SANITIZE_ADDRESS__) && !defined(__CUDACC__)
189189
TORCH_INTERNAL_ASSERT(FuncPtr::func_ptr() != nullptr, "Kernel function cannot be nullptr");
190190
#else
@@ -207,7 +207,7 @@ inline KernelFunction KernelFunction::makeFromUnboxedFunction(FuncPtr func_ptr)
207207
template<bool AllowLegacyTypes, class FuncType>
208208
inline KernelFunction KernelFunction::makeFromUnboxedRuntimeFunction(FuncType* func) {
209209
static_assert(guts::is_function_type<FuncType>::value, "Tried to call KernelFunction::makeFromUnboxedRuntimeFunction with a non-function type.");
210-
static_assert(!std::is_same<FuncType, BoxedKernelFunction>::value, "Tried to call KernelFunction::makeFromUnboxedRuntimeFunction with a boxed function pointer. Please use KernelFunction::makeFromBoxedFunction instead.");
210+
static_assert(!std::is_same_v<FuncType, BoxedKernelFunction>, "Tried to call KernelFunction::makeFromUnboxedRuntimeFunction with a boxed function pointer. Please use KernelFunction::makeFromBoxedFunction instead.");
211211
TORCH_INTERNAL_ASSERT(func != nullptr, "Kernel function cannot be nullptr");
212212

213213
return makeFromUnboxedFunctor<AllowLegacyTypes, impl::WrapFunctionIntoRuntimeFunctor<std::decay_t<FuncType>>>(

aten/src/ATen/core/boxing/impl/boxing.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ struct BoxedKernelWrapper<
383383
// that the last RetCount elements are of type `Tensor&`.
384384
auto result = guts::tuple_take<ArgTuple, -RetCount>(ArgTuple{std::forward<Args>(args)...});
385385
static_assert(
386-
std::is_same<Result, decltype(result)>::value,
386+
std::is_same_v<Result, decltype(result)>,
387387
"The parameter list of an op returning a tuple of Tensor references "
388388
"must end with an equal number of Tensor reference parameters."
389389
);

0 commit comments

Comments
 (0)