From -8009146595163722601 X-Google-Thread: f78e5,4176870a6d7b2d6 X-Google-Attributes: gidf78e5,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!peer01.cox.net!cox.net!news-hub.cableinet.net!blueyonder!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!stump.algebra.com!devnull From: bekkah@web.de (Helium) Newsgroups: comp.std.c++ Subject: Re: Union fun Date: Mon, 25 Oct 2004 18:22:01 GMT Organization: http://groups.google.com Lines: 41 Sender: mail2news@demon.net Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++) Message-ID: <194c1211.0410220336.5bdc63f9@posting.google.com> References: <1a0929fa.0410191124.162d57ee@posting.google.com> NNTP-Posting-Host: news.news.demon.net Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: news.demon.co.uk 1098728558 19410 158.152.254.254 (25 Oct 2004 18:22:38 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Mon, 25 Oct 2004 18:22:38 +0000 (UTC) X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov) X-Virus-Scanned: by amavisd-new at cs.mu.OZ.AU X-Received: (from fjh@localhost) by mulga.cs.mu.OZ.AU (8.12.10+Sun/8.12.9/Submit) id i9PIM1mp014114; Tue, 26 Oct 2004 04:22:01 +1000 (EST) X-Path: comp-std-cpp-robomod!not-for-mail X-NNTP-Posting-Date: Fri, 22 Oct 2004 11:36:34 +0000 (UTC) X-Delivered-To: std-c++@ucar.edu X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f X-Newsgroups: comp.std.c++ Xref: g2news1.google.com comp.std.c++:3157 You come from a functional language that supports discriminated unions, right? > Basically, there's a heap of machinery there of no use > to me. I'm not writing C++ .. I'm generating it. > > Here's my current variant type: > > //VARIANTS > struct _uctor_ > { > int variant; > void *data; > _uctor_() : variant(-1), data(0) {} > _uctor_(int i, void *d) : variant(i), data(d) {} > }; > > I'm forced to use the tagged pointer implementation > contrary to the design requirements. I'd love to > replace that void* with an actual union. > > In some other places, I need just an actual union > without a variant tag (the program counter is enough). > > In both cases, it would work if I just stuck to > supporting C. What about something like: You use a strcut containing a char-array. It's size is that of the largest object you want to store (-> sizeof()). Than you create objects using placement new in this array (and you destroy them manually calleng thir destructor). --- [ comp.std.c++ is moderated. To submit articles, try just posting with ] [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]