From: Marco Costalba Date: Wed, 21 Jan 2015 12:18:19 +0000 (+0100) Subject: Explicitly defaulted and deleted members X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=96e36a789708164b14c873cdb2e0acac9aca57e7 Explicitly defaulted and deleted members Better than a bit obscure implicit ones. No functional change. --- diff --git a/src/misc.h b/src/misc.h index 9241834f..e3fb6435 100644 --- a/src/misc.h +++ b/src/misc.h @@ -45,11 +45,10 @@ namespace Time { template struct HashTable { - HashTable() : table(Size, Entry()) {} Entry* operator[](Key key) { return &table[(uint32_t)key & (Size - 1)]; } private: - std::vector table; + std::vector table = std::vector(Size); }; diff --git a/src/movepick.h b/src/movepick.h index a7b25a92..9482a89c 100644 --- a/src/movepick.h +++ b/src/movepick.h @@ -80,10 +80,10 @@ typedef Stats > MovesStats; /// to get a cut-off first. class MovePicker { - - MovePicker& operator=(const MovePicker&); // Silence a warning under MSVC - public: + MovePicker(const MovePicker&) = delete; + MovePicker& operator=(const MovePicker&) = delete; + MovePicker(const Position&, Move, Depth, const HistoryStats&, Square); MovePicker(const Position&, Move, const HistoryStats&, PieceType); MovePicker(const Position&, Move, Depth, const HistoryStats&, Move*, Move*, Search::Stack*); diff --git a/src/position.h b/src/position.h index 86acd20d..0bb7b0b9 100644 --- a/src/position.h +++ b/src/position.h @@ -82,12 +82,11 @@ class Position { friend std::ostream& operator<<(std::ostream&, const Position&); - Position(const Position&); // Disable the default copy constructor - public: static void init(); - Position() {} // To define the global object RootPos + Position() = default; // To define the global object RootPos + Position(const Position&) = delete; Position(const Position& pos, Thread* th) { *this = pos; thisThread = th; } Position(const std::string& f, bool c960, Thread* th) { set(f, c960, th); } Position& operator=(const Position&); // To assign RootPos from UCI diff --git a/src/thread.h b/src/thread.h index bf16ca17..3f902dc1 100644 --- a/src/thread.h +++ b/src/thread.h @@ -73,8 +73,7 @@ struct SplitPoint { struct ThreadBase { - ThreadBase() : exit(false) {} - virtual ~ThreadBase() {} + virtual ~ThreadBase() = default; virtual void idle_loop() = 0; void notify_one(); void wait_for(volatile const bool& b); @@ -82,7 +81,7 @@ struct ThreadBase { std::thread nativeThread; std::mutex mutex; std::condition_variable sleepCondition; - volatile bool exit; + volatile bool exit = false; }; @@ -118,19 +117,17 @@ struct Thread : public ThreadBase { /// special threads: the main one and the recurring timer. struct MainThread : public Thread { - MainThread() : thinking(true) {} // Avoid a race with start_thinking() virtual void idle_loop(); - volatile bool thinking; + volatile bool thinking = true; // Avoid a race with start_thinking() }; struct TimerThread : public ThreadBase { static const int Resolution = 5; // Millisec between two check_time() calls - TimerThread() : run(false) {} virtual void idle_loop(); - bool run; + bool run = false; }; diff --git a/src/tt.cpp b/src/tt.cpp index 66113ee8..bb49a824 100644 --- a/src/tt.cpp +++ b/src/tt.cpp @@ -32,8 +32,6 @@ TranspositionTable TT; // Our global transposition table void TranspositionTable::resize(size_t mbSize) { - assert(sizeof(Cluster) == CacheLineSize / 2); - size_t newClusterCount = size_t(1) << msb((mbSize * 1024 * 1024) / sizeof(Cluster)); if (newClusterCount == clusterCount) diff --git a/src/tt.h b/src/tt.h index 4df015c0..14f820d0 100644 --- a/src/tt.h +++ b/src/tt.h @@ -81,6 +81,8 @@ class TranspositionTable { char padding[2]; // Align to the cache line size }; + static_assert(sizeof(Cluster) == CacheLineSize / 2, "Cluster size incorrect"); + public: ~TranspositionTable() { free(mem); } void new_search() { generation8 += 4; } // Lower 2 bits are used by Bound