]> git.sesse.net Git - stockfish/commitdiff
Use C++17 variable templates for type traits
authorSebastian Buchwald <UniQP@web.de>
Mon, 25 Sep 2023 10:24:48 +0000 (12:24 +0200)
committerDisservin <disservin.social@gmail.com>
Fri, 29 Sep 2023 20:22:40 +0000 (22:22 +0200)
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

src/movepick.h
src/nnue/nnue_common.h
src/syzygy/tbprobe.cpp
src/tune.h

index 5243f89cf2c68c90f816256d76a23a7105c9281c..dd9de0b216136861648da5475e4b00557fddda5e 100644 (file)
@@ -24,7 +24,7 @@
 #include <cstdint>
 #include <cstdlib>
 #include <limits>
-#include <type_traits>
+#include <type_traits> // IWYU pragma: keep
 
 #include "movegen.h"
 #include "types.h"
@@ -70,7 +70,7 @@ struct Stats : public std::array<Stats<T, D, Sizes...>, Size>
   void fill(const T& v) {
 
     // For standard-layout 'this' points to first struct member
-    assert(std::is_standard_layout<stats>::value);
+    assert(std::is_standard_layout_v<stats>);
 
     using entry = StatsEntry<T, D>;
     entry* p = reinterpret_cast<entry*>(this);
index a42a86c980d8fb69047a3ecc871bfdf098634df2..e159c5dc3dac0f0300e572a9985404bc4b9fadde 100644 (file)
@@ -103,7 +103,7 @@ namespace Stockfish::Eval::NNUE {
       else
       {
           std::uint8_t u[sizeof(IntType)];
-          typename std::make_unsigned<IntType>::type v = 0;
+          std::make_unsigned_t<IntType> v = 0;
 
           stream.read(reinterpret_cast<char*>(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<IntType>::type v = value;
+          std::make_unsigned_t<IntType> v = value;
 
           std::size_t i = 0;
           // if constexpr to silence the warning about shift by 8
index 13d271fce8a69c32e79cc265414806a826c228ea..ffe29ce16260c809c914ff6d8db58fe3a7c0ef18 100644 (file)
@@ -102,7 +102,7 @@ constexpr Value WDL_to_value[] = {
 template<typename T, int Half = sizeof(T) / 2, int End = sizeof(T) - 1>
 inline void swap_endian(T& x)
 {
-    static_assert(std::is_unsigned<T>::value, "Argument of swap_endian not unsigned");
+    static_assert(std::is_unsigned_v<T>, "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<TBType Type>
 struct TBTable {
-    using Ret = typename std::conditional<Type == WDL, WDLScore, int>::type;
+    using Ret = std::conditional_t<Type == WDL, WDLScore, int>;
 
     static constexpr int Sides = Type == WDL ? 2 : 1;
 
index 3e94f7efc6cfebb0958884a9b8800a2f5986e7dc..dde03b324eac0449e4f124df236546ac6a7c8a27 100644 (file)
@@ -22,7 +22,7 @@
 #include <cstddef>
 #include <memory>
 #include <string>
-#include <type_traits>
+#include <type_traits> // IWYU pragma: keep
 #include <utility>
 #include <vector>
 
@@ -96,11 +96,11 @@ class Tune {
   template<typename T>
   struct Entry : public EntryBase {
 
-    static_assert(!std::is_const<T>::value, "Parameter cannot be const!");
+    static_assert(!std::is_const_v<T>, "Parameter cannot be const!");
 
-    static_assert(   std::is_same<T,   int>::value
-                  || std::is_same<T, Value>::value
-                  || std::is_same<T, PostUpdate>::value, "Parameter type not supported!");
+    static_assert(   std::is_same_v<T, int>
+                  || std::is_same_v<T, Value>
+                  || std::is_same_v<T, PostUpdate>, "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