]> git.saurik.com Git - bison.git/commitdiff
variants: document move and swap
authorTheophile Ranquet <ranquet@lrde.epita.fr>
Fri, 11 Jan 2013 11:38:35 +0000 (12:38 +0100)
committerTheophile Ranquet <ranquet@lrde.epita.fr>
Fri, 11 Jan 2013 17:57:10 +0000 (18:57 +0100)
* data/variant.hh (swap): Doc.
(build): Rename as...
(move): This, more coherent naming with clearer meaning.
* data/c++.m4 (move): Adjust.

data/c++.m4
data/variant.hh

index 4fb280517b19960660cc43267e8d27a4d53df5cc..855099f7913757d7f789817092122740c378ebb4 100644 (file)
@@ -306,7 +306,7 @@ m4_define([b4_public_types_define],
   {
     this->type = s.type_get ();]b4_locations_if([
     location = s.location;])[
-    ]b4_variant_if([b4_symbol_variant([s.type_get ()], [value], [build],
+    ]b4_variant_if([b4_symbol_variant([s.type_get ()], [value], [move],
                                       [s.value])],
                    [value = s.value;])[
   }
index 4317abaf489009e671defb89c0b679f2e7a0f4e9..41286c5b9c0e98e47516d91dacf75a155ff06b33 100644 (file)
@@ -161,7 +161,12 @@ m4_define([b4_variant_define],
     }
 
     /// Swap the content with \a other, of same type.
-    /// Both variants must be built beforehand.
+    /// Both variants must be built beforehand, because swapping the actual
+    /// data requires reading it (with as()), and this is not possible on
+    /// unconstructed variants: it would require some dynamic testing, which
+    /// should not be the variant's responsability.
+    /// Swapping between built and ((possibly) non-built is done with
+    /// variant::move ().
     template <typename T>
     inline void
     swap (variant<S>& other)
@@ -176,8 +181,9 @@ m4_define([b4_variant_define],
     /// Destroys \a other.
     template <typename T>
     inline void
-    build (variant<S>& other)
-    {
+    move (variant<S>& other)
+    {]b4_parse_assert_if([
+      YYASSERT (! built);])[
       build<T>();
       swap<T>(other);
       other.destroy<T>();