c++: prefer 'emplace' to 'build'

When we introduced variants in Bison, C++ did not have the 'emplace'
functions, and we chose 'build'.  Let's align with modern C++ and
promote 'emplace' rather than 'build'.

* data/lalr1.cc, data/variant.hh (emplace): New.
(build): Deprecate in favor of emplace.
* doc/bison.texi: Adjust.
This commit is contained in:
Akim Demaille
2018-10-20 10:32:27 +02:00
parent e7b709ab0b
commit 42f0b949ec
3 changed files with 30 additions and 12 deletions

View File

@@ -10835,12 +10835,12 @@ of alternative types such as @samp{$<int>2} or @samp{$<std::string>$}, even
in midrule actions. It is mandatory to use typed midrule actions
(@pxref{Typed Midrule Actions}).
@deftypemethod {semantic_type} {T&} build<T> ()
@deftypemethod {semantic_type} {T&} emplace<T> ()
Initialize, but leave empty. Returns the address where the actual value may
be stored. Requires that the variant was not initialized yet.
@end deftypemethod
@deftypemethod {semantic_type} {T&} build<T> (const T& @var{t})
@deftypemethod {semantic_type} {T&} emplace<T> (const T& @var{t})
Initialize, and copy-construct from @var{t}.
@end deftypemethod
@@ -11166,11 +11166,11 @@ initialized. So the code would look like:
@example
[0-9]+ @{
yylval->build<int> () = text_to_int (yytext);
yylval->emplace<int> () = text_to_int (yytext);
return yy::parser::token::INTEGER;
@}
[a-z]+ @{
yylval->build<std::string> () = yytext;
yylval->emplace<std::string> () = yytext;
return yy::parser::token::IDENTIFIER;
@}
@end example
@@ -11180,11 +11180,11 @@ or
@example
[0-9]+ @{
yylval->build (text_to_int (yytext));
yylval->emplace (text_to_int (yytext));
return yy::parser::token::INTEGER;
@}
[a-z]+ @{
yylval->build (yytext);
yylval->emplace (yytext);
return yy::parser::token::IDENTIFIER;
@}
@end example