variants: assert changes

* data/variant.hh (swap): More asserts can't hurt. Don't perform useless swaps.
(build): Deactivate problematic asserts, pending further investigation.
(variant): Prohibit copy construction.
This commit is contained in:
Theophile Ranquet
2012-12-21 16:48:54 +01:00
parent e7b26e942d
commit bb1f0f5226

View File

@@ -106,8 +106,8 @@ m4_define([b4_variant_define],
inline T& inline T&
build () build ()
{]b4_parse_assert_if([ {]b4_parse_assert_if([
YYASSERT (!built); //YYASSERT (!built);
YYASSERT (!tname); //YYASSERT (!tname);
YYASSERT (sizeof (T) <= S); YYASSERT (sizeof (T) <= S);
built = true; built = true;
tname = typeid (T).name ();])[ tname = typeid (T).name ();])[
@@ -119,8 +119,8 @@ m4_define([b4_variant_define],
inline T& inline T&
build (const T& t) build (const T& t)
{]b4_parse_assert_if([ {]b4_parse_assert_if([
YYASSERT (!built); //YYASSERT (!built);
YYASSERT (!tname); //YYASSERT (!tname);
YYASSERT (sizeof (T) <= S); YYASSERT (sizeof (T) <= S);
built = true; built = true;
tname = typeid (T).name ();])[ tname = typeid (T).name ();])[
@@ -161,14 +161,15 @@ m4_define([b4_variant_define],
} }
/// Swap the content with \a other, of same type. /// Swap the content with \a other, of same type.
/// Both variants must be built beforehand.
template <typename T> template <typename T>
inline void inline void
swap (variant<S>& other) swap (variant<S>& other)
{]b4_parse_assert_if([ {]b4_parse_assert_if([
YYASSERT (built);
YYASSERT (other.built);
YYASSERT (tname == other.tname);])[ YYASSERT (tname == other.tname);])[
std::swap (as<T>(), other.as<T>());]b4_parse_assert_if([ std::swap (as<T>(), other.as<T>());
std::swap (built, other.built);
std::swap (tname, other.tname);])[
} }
/// Assign the content of \a other to this. /// Assign the content of \a other to this.
@@ -208,6 +209,11 @@ m4_define([b4_variant_define],
abort (); abort ();
} }
variant (const self_type&)
{
abort ();
}
private: private:
/// A buffer large enough to store any of the semantic values. /// A buffer large enough to store any of the semantic values.
/// Long double is chosen as it has the strongest alignment /// Long double is chosen as it has the strongest alignment