X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/bb1f0f52264dffe36595c65cde310ce965ec1df6..aedcb6c095347f71206ed9410ad27907b4be903e:/data/variant.hh diff --git a/data/variant.hh b/data/variant.hh index 184485c6..1b033886 100644 --- a/data/variant.hh +++ b/data/variant.hh @@ -1,6 +1,6 @@ # C++ skeleton for Bison -# Copyright (C) 2002-2012 Free Software Foundation, Inc. +# Copyright (C) 2002-2013 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -95,7 +95,6 @@ m4_define([b4_variant_define], typedef variant self_type; /// Empty construction. - inline variant ()]b4_parse_assert_if([ : built (false) , tname (YY_NULL)])[ @@ -103,7 +102,7 @@ m4_define([b4_variant_define], /// Instantiate a \a T in here. template - inline T& + T& build () {]b4_parse_assert_if([ //YYASSERT (!built); @@ -116,7 +115,7 @@ m4_define([b4_variant_define], /// Instantiate a \a T in here from \a t. template - inline T& + T& build (const T& t) {]b4_parse_assert_if([ //YYASSERT (!built); @@ -129,7 +128,6 @@ m4_define([b4_variant_define], /// Construct and fill. template - inline variant (const T& t)]b4_parse_assert_if([ : built (true) , tname (typeid (T).name ())])[ @@ -140,7 +138,7 @@ m4_define([b4_variant_define], /// Accessor to a built \a T. template - inline T& + T& as () {]b4_parse_assert_if([ YYASSERT (built); @@ -151,7 +149,7 @@ m4_define([b4_variant_define], /// Const accessor to a built \a T (for %printer). template - inline const T& + const T& as () const {]b4_parse_assert_if([ YYASSERT (built); @@ -161,9 +159,14 @@ 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 + void swap (variant& other) {]b4_parse_assert_if([ YYASSERT (built); @@ -175,9 +178,10 @@ m4_define([b4_variant_define], /// Assign the content of \a other to this. /// Destroys \a other. template - inline void - build (variant& other) - { + void + move (variant& other) + {]b4_parse_assert_if([ + YYASSERT (! built);])[ build(); swap(other); other.destroy(); @@ -186,7 +190,7 @@ m4_define([b4_variant_define], /// Copy the content of \a other to this. /// Destroys \a other. template - inline void + void copy (const variant& other) { build (other.as ()); @@ -194,7 +198,7 @@ m4_define([b4_variant_define], /// Destroy the stored \a T. template - inline void + void destroy () { as ().~T ();]b4_parse_assert_if([ @@ -203,7 +207,7 @@ m4_define([b4_variant_define], } /// Prohibit blind copies. - // private: + private: self_type& operator=(const self_type&) { abort ();