examples: improve the output of the "variant" example
authorAkim Demaille <akim@lrde.epita.fr>
Thu, 19 Sep 2013 13:20:22 +0000 (15:20 +0200)
committerAkim Demaille <akim@lrde.epita.fr>
Thu, 19 Sep 2013 13:57:59 +0000 (15:57 +0200)
* examples/variant.yy: Improve the printing of lists.

examples/variant.yy

index 9413cbc..fd551cc 100644 (file)
@@ -16,7 +16,7 @@
 */
 
 %debug
-%skeleton "lalr1.cc"
+%language "c++"
 %defines
 %define api.token.constructor
 %define api.value.type variant
@@ -48,11 +48,17 @@ typedef std::list<std::string> strings_type;
   namespace std
   {
     std::ostream&
-    operator<< (std::ostream& o, const strings_type& s)
+    operator<< (std::ostream& o, const strings_type& ss)
     {
-      std::copy (s.begin (), s.end (),
-                 std::ostream_iterator<strings_type::value_type> (o, "\n"));
-      return o;
+      o << "(" << &ss << ") {";
+      const char *sep = "";
+      for (strings_type::const_iterator i = ss.begin(), end = ss.end();
+           i != end; ++i)
+        {
+          o << sep << *i;
+          sep = ", ";
+        }
+      return o << "}";
     }
   }