From: Sebastian Buchwald Date: Mon, 25 Sep 2023 10:24:48 +0000 (+0200) Subject: Use C++17 variable templates for type traits X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=4f0fecad8a0f5258114f63f0ac0c905a54d65219 Use C++17 variable templates for type traits The C++17 variable templates are slightly more readable and allow us to remove the typename keyword in a few cases. closes https://github.com/official-stockfish/Stockfish/pull/4806 No functional change --- diff --git a/src/movepick.h b/src/movepick.h index 5243f89c..dd9de0b2 100644 --- a/src/movepick.h +++ b/src/movepick.h @@ -24,7 +24,7 @@ #include #include #include -#include +#include // IWYU pragma: keep #include "movegen.h" #include "types.h" @@ -70,7 +70,7 @@ struct Stats : public std::array, Size> void fill(const T& v) { // For standard-layout 'this' points to first struct member - assert(std::is_standard_layout::value); + assert(std::is_standard_layout_v); using entry = StatsEntry; entry* p = reinterpret_cast(this); diff --git a/src/nnue/nnue_common.h b/src/nnue/nnue_common.h index a42a86c9..e159c5dc 100644 --- a/src/nnue/nnue_common.h +++ b/src/nnue/nnue_common.h @@ -103,7 +103,7 @@ namespace Stockfish::Eval::NNUE { else { std::uint8_t u[sizeof(IntType)]; - typename std::make_unsigned::type v = 0; + std::make_unsigned_t v = 0; stream.read(reinterpret_cast(u), sizeof(IntType)); for (std::size_t i = 0; i < sizeof(IntType); ++i) @@ -128,7 +128,7 @@ namespace Stockfish::Eval::NNUE { else { std::uint8_t u[sizeof(IntType)]; - typename std::make_unsigned::type v = value; + std::make_unsigned_t v = value; std::size_t i = 0; // if constexpr to silence the warning about shift by 8 diff --git a/src/syzygy/tbprobe.cpp b/src/syzygy/tbprobe.cpp index 13d271fc..ffe29ce1 100644 --- a/src/syzygy/tbprobe.cpp +++ b/src/syzygy/tbprobe.cpp @@ -102,7 +102,7 @@ constexpr Value WDL_to_value[] = { template inline void swap_endian(T& x) { - static_assert(std::is_unsigned::value, "Argument of swap_endian not unsigned"); + static_assert(std::is_unsigned_v, "Argument of swap_endian not unsigned"); uint8_t tmp, *c = (uint8_t*)&x; for (int i = 0; i < Half; ++i) @@ -332,7 +332,7 @@ struct PairsData { // first access, when the corresponding file is memory mapped. template struct TBTable { - using Ret = typename std::conditional::type; + using Ret = std::conditional_t; static constexpr int Sides = Type == WDL ? 2 : 1; diff --git a/src/tune.h b/src/tune.h index 3e94f7ef..dde03b32 100644 --- a/src/tune.h +++ b/src/tune.h @@ -22,7 +22,7 @@ #include #include #include -#include +#include // IWYU pragma: keep #include #include @@ -96,11 +96,11 @@ class Tune { template struct Entry : public EntryBase { - static_assert(!std::is_const::value, "Parameter cannot be const!"); + static_assert(!std::is_const_v, "Parameter cannot be const!"); - static_assert( std::is_same::value - || std::is_same::value - || std::is_same::value, "Parameter type not supported!"); + static_assert( std::is_same_v + || std::is_same_v + || std::is_same_v, "Parameter type not supported!"); Entry(const std::string& n, T& v, const SetRange& r) : name(n), value(v), range(r) {} void operator=(const Entry&) = delete; // Because 'value' is a reference