]> git.saurik.com Git - bison.git/blobdiff - data/variant.hh
c++: m4 stylistic change
[bison.git] / data / variant.hh
index 1ebcfe80eaa8e0a5731538623d7afea6e2486a45..5ff0c54da82a0cce588ce90885d5b43591d8c756 100644 (file)
@@ -1,6 +1,6 @@
 # C++ skeleton for Bison
 
-# Copyright (C) 2002-2012 Free Software Foundation, Inc.
+# Copyright (C) 2002-2013 Free Software Foundation, Inc.
 
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -106,8 +106,8 @@ m4_define([b4_variant_define],
     inline T&
     build ()
     {]b4_parse_assert_if([
-      YYASSERT (!built);
-      YYASSERT (!tname);
+      //YYASSERT (!built);
+      //YYASSERT (!tname);
       YYASSERT (sizeof (T) <= S);
       built = true;
       tname = typeid (T).name ();])[
@@ -119,8 +119,8 @@ m4_define([b4_variant_define],
     inline T&
     build (const T& t)
     {]b4_parse_assert_if([
-      YYASSERT (!built);
-      YYASSERT (!tname);
+      //YYASSERT (!built);
+      //YYASSERT (!tname);
       YYASSERT (sizeof (T) <= S);
       built = true;
       tname = typeid (T).name ();])[
@@ -161,22 +161,29 @@ m4_define([b4_variant_define],
     }
 
     /// Swap the content with \a other, of same type.
+    /// 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)
     {]b4_parse_assert_if([
+      YYASSERT (built);
+      YYASSERT (other.built);
       YYASSERT (tname == other.tname);])[
-      std::swap (as<T>(), other.as<T>());]b4_parse_assert_if([
-      std::swap (built, other.built);
-      std::swap (tname, other.tname);])[
+      std::swap (as<T>(), other.as<T>());
     }
 
     /// Assign the content of \a other to this.
     /// 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>();
@@ -202,12 +209,17 @@ m4_define([b4_variant_define],
     }
 
     /// Prohibit blind copies.
-    //  private:
+    private:
     self_type& operator=(const self_type&)
     {
       abort ();
     }
 
+    variant (const self_type&)
+    {
+      abort ();
+    }
+
   private:
     /// A buffer large enough to store any of the semantic values.
     /// Long double is chosen as it has the strongest alignment