Hi Victor!

> Le 24 oct. 2018 à 18:14, Victor Khomenko <[email protected]> a 
> écrit :
> 
>    ** No need to implement to_string() in the simple example, better use 
> https://en.cppreference.com/w/cpp/string/basic_string/to_string

Gee… Of course.  It’s there because it started in C++98, and I
forgot to get rid of it.  I installed this:

commit 5b879c898002d7e62acd647039aa787fd091e85a
Author: Akim Demaille <[email protected]>
Date:   Wed Oct 24 18:49:04 2018 +0200

    c++: std::to_string is available in C++11
    
    Reported by Victor Khomenko.
    http://lists.gnu.org/archive/html/bug-bison/2018-10/msg00033.html
    
    * doc/bison.texi, examples/c++/variant-11.yy: Use std::to_string
    instead of ours.

diff --git a/doc/bison.texi b/doc/bison.texi
index f6d240da..91b472b7 100644
--- a/doc/bison.texi
+++ b/doc/bison.texi
@@ -10672,48 +10672,8 @@ Variants}):
 %define api.value.type variant
 @end example
 
-Our list of strings will be built from two types of items: numbers and
-strings:
-
-@comment file: c++/simple.yy: 2
-@example
-%type <std::string> item;
-%token <std::string> TEXT;
-%token <int> NUMBER;
-@group
-item:
-  TEXT
-| NUMBER  @{ $$ = to_string ($1); @}
-;
-@end group 
-@end example
-
-In the case of @code{TEXT}, the implicit default action applies: @w{@code{$$
-= $1}.}  We recommend that you keep the actions simple, and move details
-into auxiliary functions, as we did with @code{to_string}, which we
-implement in the prologue as follows:
-
-@comment file: c++/simple.yy: 1
-@example
-%code
-@{
-  #include <sstream>
-
-@group
-  // Convert to string.
-  template <typename T>
-  auto to_string (const T& t) -> std::string
-  @{
-    std::ostringstream o;
-    o << t;
-    return o.str ();
-  @}
-@end group
-@}
-@end example
-
 Obviously, the rule for @code{result} needs to print a vector of strings.
-Again, in the prologue, we add:
+In the prologue, we add:
 
 @comment file: c++/simple.yy: 1
 @example
@@ -10740,7 +10700,27 @@ Again, in the prologue, we add:
 
 @noindent
 You may want to move it into the @code{yy} namespace to avoid leaking it in
-your default namespace.
+your default namespace.  We recommend that you keep the actions simple, and
+move details into auxiliary functions, as we did with @code{operator<<}.
+
+Our list of strings will be built from two types of items: numbers and
+strings:
+
+@comment file: c++/simple.yy: 2
+@example
+%type <std::string> item;
+%token <std::string> TEXT;
+%token <int> NUMBER;
+@group
+item:
+  TEXT
+| NUMBER  @{ $$ = std::to_string ($1); @}
+;
+@end group
+@end example
+
+In the case of @code{TEXT}, the implicit default action applies: @w{@code{$$
+= $1}.}
 
 @sp 1
 
diff --git a/examples/c++/variant-11.yy b/examples/c++/variant-11.yy
index 4cd581ca..be38589d 100644
--- a/examples/c++/variant-11.yy
+++ b/examples/c++/variant-11.yy
@@ -69,16 +69,6 @@
     // std::make_unique is C++14.
     return string_uptr (new std::string{std::forward<Args> (args)...});
   }
-
-  // Convert to string.
-  template <typename T>
-    std::string
-    to_string (const T& t)
-  {
-    auto&& o = std::ostringstream{};
-    o << t;
-    return o.str ();
-  }
 }
 
 %token <string_uptr> TEXT;
@@ -103,7 +93,7 @@ list:
 
 item:
   TEXT
-| NUMBER  { $$ = make_string_uptr (to_string ($1)); }
+| NUMBER  { $$ = make_string_uptr (std::to_string ($1)); }
 ;
 %%
 



Reply via email to