mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
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:
@@ -862,7 +862,7 @@ b4_dollar_popdef])[]dnl
|
||||
/* Variants are always initialized to an empty instance of the
|
||||
correct type. The default '$$ = $1' action is NOT applied
|
||||
when using variants. */
|
||||
b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [build])], [
|
||||
b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [emplace])], [
|
||||
/* If YYLEN is nonzero, implement the default value of the
|
||||
action: '$$ = $1'. Otherwise, use the top of the stack.
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ m4_define([b4_variant_define],
|
||||
/// Instantiate an empty \a T in here.
|
||||
template <typename T>
|
||||
T&
|
||||
build ()
|
||||
emplace ()
|
||||
{]b4_parse_assert_if([
|
||||
YYASSERT (!yytypeid_);
|
||||
YYASSERT (sizeof (T) <= S);
|
||||
@@ -128,7 +128,7 @@ m4_define([b4_variant_define],
|
||||
/// Instantiate a \a T in here from \a t.
|
||||
template <typename T>
|
||||
T&
|
||||
build (const T& t)
|
||||
emplace (const T& t)
|
||||
{]b4_parse_assert_if([
|
||||
YYASSERT (!yytypeid_);
|
||||
YYASSERT (sizeof (T) <= S);
|
||||
@@ -136,6 +136,24 @@ m4_define([b4_variant_define],
|
||||
return *new (yyas_<T> ()) T (t);
|
||||
}
|
||||
|
||||
/// Instantiate an empty \a T in here.
|
||||
/// Obsolete, use emplace.
|
||||
template <typename T>
|
||||
T&
|
||||
build ()
|
||||
{
|
||||
return emplace<T> ();
|
||||
}
|
||||
|
||||
/// Instantiate a \a T in here from \a t.
|
||||
/// Obsolete, use emplace.
|
||||
template <typename T>
|
||||
T&
|
||||
build (const T& t)
|
||||
{
|
||||
return emplace<T> (t);
|
||||
}
|
||||
|
||||
/// Accessor to a built \a T.
|
||||
template <typename T>
|
||||
T&
|
||||
@@ -182,7 +200,7 @@ m4_define([b4_variant_define],
|
||||
void
|
||||
move (self_type& other)
|
||||
{
|
||||
build<T> ();
|
||||
emplace<T> ();
|
||||
# if defined __cplusplus && 201103L <= __cplusplus
|
||||
as<T> () = std::move (other.as<T> ());
|
||||
# else
|
||||
@@ -197,7 +215,7 @@ m4_define([b4_variant_define],
|
||||
void
|
||||
move (self_type&& other)
|
||||
{
|
||||
build<T> ();
|
||||
emplace<T> ();
|
||||
as<T> () = std::move (other.as<T> ());
|
||||
other.destroy<T> ();
|
||||
}
|
||||
@@ -208,7 +226,7 @@ m4_define([b4_variant_define],
|
||||
void
|
||||
copy (const self_type& other)
|
||||
{
|
||||
build<T> (other.as<T> ());
|
||||
emplace<T> (other.as<T> ());
|
||||
}
|
||||
|
||||
/// Destroy the stored \a T.
|
||||
|
||||
Reference in New Issue
Block a user