# YYTYPE.
m4_define([b4_symbol_variant],
[m4_pushdef([b4_dollar_dollar],
- [$2.$3< $][3 >(m4_shift3($@))])dnl
+ [$2.$3< $][3 > (m4_shift3($@))])dnl
switch ($1)
{
b4_type_foreach([b4_type_action_])[]dnl
: tname (typeid (T).name ())])[
{
YYASSERT (sizeof (T) <= S);
- new (buffer.raw) T (t);
+ new (as_ <T> ()) T (t);
}
/// Destruction, allowed only if empty.
YYASSERT (!tname);
YYASSERT (sizeof (T) <= S);
tname = typeid (T).name ();])[
- return *new (buffer.raw) T;
+ return *new (as_<T> ()) T;
}
/// Instantiate a \a T in here from \a t.
YYASSERT (!tname);
YYASSERT (sizeof (T) <= S);
tname = typeid (T).name ();])[
- return *new (buffer.raw) T (t);
+ return *new (as_<T> ()) T (t);
}
/// Accessor to a built \a T.
{]b4_parse_assert_if([
YYASSERT (tname == typeid (T).name ());
YYASSERT (sizeof (T) <= S);])[
- {
- void *dummy = buffer.raw;
- return *static_cast<T*> (dummy);
- }
+ return *as_<T> ();
}
/// Const accessor to a built \a T (for %printer).
{]b4_parse_assert_if([
YYASSERT (tname == typeid (T).name ());
YYASSERT (sizeof (T) <= S);])[
- {
- const void *dummy = buffer.raw;
- return *static_cast<const T*> (dummy);
- }
+ return *as_<T> ();
}
/// Swap the content with \a other, of same type.
{]b4_parse_assert_if([
YYASSERT (tname);
YYASSERT (tname == other.tname);])[
- std::swap (as<T>(), other.as<T>());
+ std::swap (as<T> (), other.as<T> ());
}
/// Move the content of \a other to this.
move (self_type& other)
{]b4_parse_assert_if([
YYASSERT (!tname);])[
- build<T>();
- swap<T>(other);
- other.destroy<T>();
+ build<T> ();
+ swap<T> (other);
+ other.destroy<T> ();
}
/// Copy the content of \a other to this.
self_type& operator=(const self_type&);
variant (const self_type&);
+ /// Accessor to raw memory as \a T.
+ template <typename T>
+ T*
+ as_ ()
+ {
+ void *yyp = buffer.raw;
+ return static_cast<T*> (yyp);
+ }
+
+ /// Const accessor to raw memory as \a T.
+ template <typename T>
+ const T*
+ as_ () const
+ {
+ const void *yyp = buffer.raw;
+ return static_cast<const T*> (yyp);
+ }
+
/// A buffer large enough to store any of the semantic values.
/// Long double is chosen as it has the strongest alignment
/// constraints.
} buffer;]b4_parse_assert_if([
/// Whether the content is built: if defined, the name of the stored type.
- const char* tname;])[
+ const char *tname;])[
};
]])
# ----------------------------
m4_define([b4_symbol_value],
[m4_ifval([$2],
- [$1.as< $2 >()],
+ [$1.as< $2 > ()],
[$1])])
# b4_symbol_value_template(VAL, [TYPE])
# Same as b4_symbol_value, but used in a template method.
m4_define([b4_symbol_value_template],
[m4_ifval([$2],
- [$1.template as< $2 >()],
+ [$1.template as< $2 > ()],
[$1])])