You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
4cd95a2 refactor: modernize remaining outdated trait patterns (Lőrinc)
ab2b67f scripted-diff: modernize outdated trait patterns - values (Lőrinc)
8327889 scripted-diff: modernize outdated trait patterns - types (Lőrinc)
Pull request description:
The use of [`std::underlying_type_t<T>`](https://en.cppreference.com/w/cpp/types/underlying_type) or [`std::is_enum_v<T>`](https://en.cppreference.com/w/cpp/types/is_enum) (and similar ones, introduced in C++14) replace the `typename std::underlying_type<T>::type` and `std::is_enum<T>::value` constructs (available in C++11).
The `_t` and `_v` helper alias templates offer a more concise way to extract the type and value directly.
I've modified the instances I found in the codebase one-by-one (noticed them while investigating bitcoin#31868), and afterwards extracted scripted diff commits to do the trivial ones automatically.
The last commit contains the values that were easier done manually.
I've excluded changes from `src/bench/nanobench.h`, `src/leveldb`, `src/minisketch`, `src/span.h` and `src/sync.h` - let me know if you think they should be included instead.
A few of the code changes can also be reproduced by clang-tidy (but not all of them):
```bash
cmake -B build -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DBUILD_BENCH=ON -DBUILD_FUZZ_BINARY=ON -DBUILD_FOR_FUZZING=ON && cmake --build build -j$(nproc)
run-clang-tidy -quiet -p build -j $(nproc) -checks='-*,modernize-type-traits' -fix $(git grep -lE '::(value|type)' ./src ':(exclude)src/bench/nanobench.h' ':(exclude)src/leveldb' ':(exclude)src/minisketch' ':(exclude)src/span.h' ':(exclude)src/sync.h')
```
ACKs for top commit:
laanwj:
Concept and code review ACK 4cd95a2
Tree-SHA512: a4bcf0f267c0f4e02983b4d548ed6f58d464ec379ac5cd1f998b9ec0cf698b53a9f2557a05a342b661f1d94adefc9a0ce2dc8f764d49453aaea95451e2c4c581
static_assert(!std::is_same<typenamestd::decay<T>::type, char*>::value, "Calling operator<<(CSHA512, char*) is probably not what you want");
74
-
static_assert(!std::is_same<typenamestd::decay<T>::type, unsignedchar*>::value, "Calling operator<<(CSHA512, unsigned char*) is probably not what you want");
75
-
static_assert(!std::is_same<typenamestd::decay<T>::type, constchar*>::value, "Calling operator<<(CSHA512, const char*) is probably not what you want");
76
-
static_assert(!std::is_same<typenamestd::decay<T>::type, constunsignedchar*>::value, "Calling operator<<(CSHA512, const unsigned char*) is probably not what you want");
73
+
static_assert(!std::is_same_v<std::decay_t<T>, char*>, "Calling operator<<(CSHA512, char*) is probably not what you want");
74
+
static_assert(!std::is_same_v<std::decay_t<T>, unsignedchar*>, "Calling operator<<(CSHA512, unsigned char*) is probably not what you want");
75
+
static_assert(!std::is_same_v<std::decay_t<T>, constchar*>, "Calling operator<<(CSHA512, const char*) is probably not what you want");
76
+
static_assert(!std::is_same_v<std::decay_t<T>, constunsignedchar*>, "Calling operator<<(CSHA512, const unsigned char*) is probably not what you want");
0 commit comments