From 6656c9b52a306b394fb6529f735924db0f08c1a2 Mon Sep 17 00:00:00 2001 From: Theophile Ranquet Date: Fri, 11 Jan 2013 12:38:35 +0100 Subject: [PATCH] variants: document move and swap * data/variant.hh (swap): Doc. (build): Rename as... (move): This, more coherent naming with clearer meaning. * data/c++.m4 (move): Adjust. --- data/c++.m4 | 2 +- data/variant.hh | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/data/c++.m4 b/data/c++.m4 index 4fb28051..855099f7 100644 --- a/data/c++.m4 +++ b/data/c++.m4 @@ -306,7 +306,7 @@ m4_define([b4_public_types_define], { this->type = s.type_get ();]b4_locations_if([ location = s.location;])[ - ]b4_variant_if([b4_symbol_variant([s.type_get ()], [value], [build], + ]b4_variant_if([b4_symbol_variant([s.type_get ()], [value], [move], [s.value])], [value = s.value;])[ } diff --git a/data/variant.hh b/data/variant.hh index 4317abaf..41286c5b 100644 --- a/data/variant.hh +++ b/data/variant.hh @@ -161,7 +161,12 @@ m4_define([b4_variant_define], } /// Swap the content with \a other, of same type. - /// Both variants must be built beforehand. + /// Both variants must be built beforehand, because swapping the actual + /// data requires reading it (with as()), and this is not possible on + /// unconstructed variants: it would require some dynamic testing, which + /// should not be the variant's responsability. + /// Swapping between built and ((possibly) non-built is done with + /// variant::move (). template inline void swap (variant& other) @@ -176,8 +181,9 @@ m4_define([b4_variant_define], /// Destroys \a other. template inline void - build (variant& other) - { + move (variant& other) + {]b4_parse_assert_if([ + YYASSERT (! built);])[ build(); swap(other); other.destroy(); -- 2.45.2