~ubuntu-branches/ubuntu/trusty/c++-annotations/trusty

« back to all changes in this revision

Viewing changes to yo/containers/uniondestructor.yo

  • Committer: Package Import Robot
  • Author(s): tony mancill, Frank B. Brokken, tony mancill
  • Date: 2012-02-28 00:50:21 UTC
  • mfrom: (1.1.19)
  • Revision ID: package-import@ubuntu.com-20120228005021-sz7nnodntkvgh7qf
Tags: 9.2.1-1
[ Frank B. Brokken ]
* New upstream release (using flexc++, reauthored polymorphic semantic
  values and unrestricted unions). Upstream release 9.2.0 is implied by
  this release.

[ tony mancill ]
* Set Standards-Version to 3.9.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Although the compiler won't provide (default) implementations for constructors
 
2
and destructors of unrestricted unions, em(we) can. The task isn't difficult,
 
3
but there are some caveats.
 
4
 
 
5
Consider our unrestricted union's destructor. It clearly should destroy
 
6
tt(u_string)'s data if that is its currently active field; but it should do
 
7
nothing if tt(u_int) is its currently active field. But how does the
 
8
destructor know what field to destroy? It doesn't as the unrestricted union
 
9
holds no information about what field is currently active.
 
10
 
 
11
Here is one way to tackle this problem:
 
12
 
 
13
If we embed the unrestricted union in a larger aggregate, like a class or a
 
14
struct, then the class or struct can be provided with a emi(tag) data member
 
15
storing the currently active union-field. The tag can be an enumeration type,
 
16
defined by the aggregate. The unrestricted union may then be controlled by the
 
17
aggregate. Under this approach we start out with an explicit empty
 
18
implementations of the destructor, as there's no way to tell the destructor
 
19
itself what field to destroy:
 
20
        verb(
 
21
    Data::Union::~Union()
 
22
    {};
 
23
        )