]> git.sesse.net Git - stockfish/commitdiff
More idiomatic signature for operator=()
authorMarco Costalba <mcostalba@gmail.com>
Thu, 5 Jul 2012 10:52:11 +0000 (11:52 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Thu, 5 Jul 2012 10:55:35 +0000 (11:55 +0100)
Return a reference instead of void so to enable
chained assignments like

"p = q = Position(...);"

Suggested by Rein Halbersma.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/position.cpp
src/position.h
src/ucioption.cpp
src/ucioption.h

index 4be0a231d5ef4226c6b4b6d3abce68b3697c363d..a425b59cc80a83520a50b7e6f9a32ec335e72a55 100644 (file)
@@ -89,7 +89,7 @@ CheckInfo::CheckInfo(const Position& pos) {
 /// object do not depend on any external data so we detach state pointer from
 /// the source one.
 
-void Position::operator=(const Position& pos) {
+Position& Position::operator=(const Position& pos) {
 
   memcpy(this, &pos, sizeof(Position));
   startState = *st;
@@ -97,6 +97,8 @@ void Position::operator=(const Position& pos) {
   nodes = 0;
 
   assert(pos_is_ok());
+
+  return *this;
 }
 
 
index 27a70aaedde51b83a25cb22a216f474dde603896..9528bb71963ac01e428fc93ca4f589bebb49e8a3 100644 (file)
@@ -97,7 +97,7 @@ public:
   Position(const Position& p) { *this = p; }
   Position(const Position& p, Thread* t) { *this = p; thisThread = t; }
   Position(const std::string& f, bool c960, Thread* t) { from_fen(f, c960, t); }
-  void operator=(const Position&);
+  Position& operator=(const Position&);
 
   // Text input/output
   void from_fen(const std::string& fen, bool isChess960, Thread* th);
index 763db556654e4c87828854bc7290d056ba8038da..58f3dbc0c663a6cd0412f913fd556191048d1c2e 100644 (file)
@@ -134,18 +134,20 @@ UCIOption::UCIOption(int v, int minv, int maxv, Fn* f) : type("spin"), min(minv)
 /// check for option's limits, but we could receive the new value directly from
 /// the user by console window, so let's check the bounds anyway.
 
-void UCIOption::operator=(const string& v) {
+UCIOption& UCIOption::operator=(const string& v) {
 
   assert(!type.empty());
 
   if (   (type != "button" && v.empty())
       || (type == "check" && v != "true" && v != "false")
       || (type == "spin" && (atoi(v.c_str()) < min || atoi(v.c_str()) > max)))
-      return;
+      return *this;
 
   if (type != "button")
       currentValue = v;
 
   if (on_change)
       (*on_change)(*this);
+
+  return *this;
 }
index c57cf021e8c681ab7c389cac8c5143e53ee97c61..0be8c7e39d4734b3cbf8ba918a4c0958ac08d4b9 100644 (file)
@@ -38,7 +38,7 @@ public:
   UCIOption(const char* v, Fn* = NULL);
   UCIOption(int v, int min, int max, Fn* = NULL);
 
-  void operator=(const std::string& v);
+  UCIOption& operator=(const std::string& v);
 
   operator int() const {
     assert(type == "check" || type == "spin");