The use of std::underlying_type_t<T>
or std::is_enum_v<T>
(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 #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
, src/sync.h
and src/test/fuzz/FuzzedDataProvider.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):
0cmake -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)
1run-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')