/// Empty construction.
variant ()]b4_parse_assert_if([
- : built (false)
- , tname (YY_NULL)])[
+ : tname (YY_NULL)])[
{}
/// Construct and fill.
template <typename T>
variant (const T& t)]b4_parse_assert_if([
- : built (true)
- , tname (typeid (T).name ())])[
+ : tname (typeid (T).name ())])[
{
YYASSERT (sizeof (T) <= S);
new (buffer.raw) T (t);
/// Destruction, allowed only if empty.
~variant ()
{]b4_parse_assert_if([
- YYASSERT (!built);
+ YYASSERT (!tname);
])[}
/// Instantiate an empty \a T in here.
T&
build ()
{]b4_parse_assert_if([
- YYASSERT (!built);
YYASSERT (!tname);
YYASSERT (sizeof (T) <= S);
- built = true;
tname = typeid (T).name ();])[
return *new (buffer.raw) T;
}
T&
build (const T& t)
{]b4_parse_assert_if([
- YYASSERT (!built);
YYASSERT (!tname);
YYASSERT (sizeof (T) <= S);
- built = true;
tname = typeid (T).name ();])[
return *new (buffer.raw) T (t);
}
T&
as ()
{]b4_parse_assert_if([
- YYASSERT (built);
YYASSERT (tname == typeid (T).name ());
YYASSERT (sizeof (T) <= S);])[
return reinterpret_cast<T&> (buffer.raw);
const T&
as () const
{]b4_parse_assert_if([
- YYASSERT (built);
YYASSERT (tname == typeid (T).name ());
YYASSERT (sizeof (T) <= S);])[
return reinterpret_cast<const T&> (buffer.raw);
void
swap (self_type& other)
{]b4_parse_assert_if([
- YYASSERT (built);
- YYASSERT (other.built);
+ YYASSERT (tname);
YYASSERT (tname == other.tname);])[
std::swap (as<T>(), other.as<T>());
}
void
move (self_type& other)
{]b4_parse_assert_if([
- YYASSERT (! built);])[
+ YYASSERT (!tname);])[
build<T>();
swap<T>(other);
other.destroy<T>();
destroy ()
{
as<T> ().~T ();]b4_parse_assert_if([
- built = false;
tname = YY_NULL;])[
}
char raw[S];
} buffer;]b4_parse_assert_if([
- /// Whether the content is built.
- bool built;
- /// If defined, the name of the stored type.
+ /// Whether the content is built: if defined, the name of the stored type.
const char* tname;])[
};
]])