]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Add comments about the implementation of 'autosprintf::operator='.
authorBruno Haible <bruno@clisp.org>
Sun, 27 Dec 2015 00:03:56 +0000 (01:03 +0100)
committerBruno Haible <bruno@clisp.org>
Mon, 24 Oct 2016 22:18:22 +0000 (00:18 +0200)
* gettext-runtime/libasprintf/autosprintf.in.h (autosprintf::operator=): Add
comments. Rename parameter.
* gettext-runtime/libasprintf/autosprintf.cc (autosprintf::operator=): Likewise.

gettext-runtime/libasprintf/autosprintf.cc
gettext-runtime/libasprintf/autosprintf.in.h

index 0c8bff1f197e0ef0d19ddc972d85f5e880cc3ad7..d194a309bf314a6953ad8211a119349e67611b40 100644 (file)
@@ -56,10 +56,12 @@ namespace gnu
     str = (src.str != NULL ? strdup (src.str) : NULL);
   }
 
-  /* Copy constructor.  Necessary because the destructor is nontrivial.  */
-  autosprintf& autosprintf::operator = (autosprintf copy)
+  /* Assignment operator.  Necessary because the destructor is nontrivial.  */
+  autosprintf& autosprintf::operator = (autosprintf temporary)
   {
-    std::swap (copy.str, this->str);
+    /* Copy-and-swap idiom.
+       See http://stackoverflow.com/questions/3279543/what-is-the-copy-and-swap-idiom  */
+    std::swap (temporary.str, this->str);
     return *this;
   }
 
index 1c9eb18a1571b40a83ce05c6a74e5344b0d96291..9c34bc92b3bc811604488c4020a3834bcd89fe33 100644 (file)
@@ -47,7 +47,8 @@ namespace gnu
                 _AUTOSPRINTF_ATTRIBUTE_FORMAT();
     /* Copy constructor.  */
     autosprintf (const autosprintf& src);
-    autosprintf& operator = (autosprintf copy);
+    /* Assignment operator.  */
+    autosprintf& operator = (autosprintf temporary);
     /* Destructor: frees the temporarily allocated string.  */
     ~autosprintf ();
     /* Conversion to string.  */