From bb1f0f52264dffe36595c65cde310ce965ec1df6 Mon Sep 17 00:00:00 2001 From: Theophile Ranquet Date: Fri, 21 Dec 2012 16:48:54 +0100 Subject: [PATCH] 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. --- data/variant.hh | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/data/variant.hh b/data/variant.hh index 1ebcfe80..184485c6 100644 --- a/data/variant.hh +++ b/data/variant.hh @@ -106,8 +106,8 @@ m4_define([b4_variant_define], inline T& build () {]b4_parse_assert_if([ - YYASSERT (!built); - YYASSERT (!tname); + //YYASSERT (!built); + //YYASSERT (!tname); YYASSERT (sizeof (T) <= S); built = true; tname = typeid (T).name ();])[ @@ -119,8 +119,8 @@ m4_define([b4_variant_define], inline T& build (const T& t) {]b4_parse_assert_if([ - YYASSERT (!built); - YYASSERT (!tname); + //YYASSERT (!built); + //YYASSERT (!tname); YYASSERT (sizeof (T) <= S); built = true; tname = typeid (T).name ();])[ @@ -161,14 +161,15 @@ m4_define([b4_variant_define], } /// Swap the content with \a other, of same type. + /// Both variants must be built beforehand. template inline void swap (variant& other) {]b4_parse_assert_if([ + YYASSERT (built); + YYASSERT (other.built); YYASSERT (tname == other.tname);])[ - std::swap (as(), other.as());]b4_parse_assert_if([ - std::swap (built, other.built); - std::swap (tname, other.tname);])[ + std::swap (as(), other.as()); } /// Assign the content of \a other to this. @@ -208,6 +209,11 @@ m4_define([b4_variant_define], abort (); } + variant (const self_type&) + { + abort (); + } + private: /// A buffer large enough to store any of the semantic values. /// Long double is chosen as it has the strongest alignment -- 2.47.2