From -3944581726493864738
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!news.zanker.org!news.clara.net!wagner.news.clara.net!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!stump.algebra.com!devnull
From: ben-public-nospam@decadentplace.org.uk (Ben Hutchings)
Newsgroups: comp.std.c++
Subject: Re: Union fun
Date: Tue, 19 Oct 2004 14:47:10 GMT
Lines: 43
Sender: mail2news@demon.net
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <slrncn9ls5.fqi.ben-public-nospam@decadentplace.org.uk>
References: <pan.2004.10.17.15.08.58.192861@nospam.com.au> <slrncn71pm.fqi.ben-public-nospam@decadentplace.org.uk> <pan.2004.10.19.01.55.50.896756@nospam.com.au>
NNTP-Posting-Host: news.news.demon.net
X-Trace: news.demon.co.uk 1098197237 2282 158.152.254.254 (19 Oct 2004 14:47:17 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Tue, 19 Oct 2004 14:47:17 +0000 (UTC)
X-Received-SPF: Received-SPF: none (mailbox10.ucsd.edu: domain of mod-submit@uni-berlin.de does not designate permitted sender hosts)
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-User-Agent: slrn/0.9.7.4 (Linux)
X-Spam-Checker-Version: SpamAssassin 2.64-mulga_r1 (2004-01-11) on 
	mulga.cs.mu.OZ.AU
X-Orig-X-Trace: news.uni-berlin.de HQ2huDmtet2RYdtal6IOYwHio4DcUvKRTk6gtqoZqV6MxRjqc=
X-Spam-Status: No, hits=-4.9 required=5.0 tests=AWL,BAYES_00 autolearn=ham 
	version=2.64-mulga_r1
X-Reply-To: Ben Hutchings <ben@decadentplace.org.uk>
X-Received: (from fjh@localhost)
	by mulga.cs.mu.OZ.AU (8.12.10+Sun/8.12.9/Submit) id i9JElAPg015739;
	Wed, 20 Oct 2004 00:47:10 +1000 (EST)
X-Path: comp-std-cpp-robomod!not-for-mail
X-Spam-Level: 
X-Delivered-To: std-c++@ucar.edu
X-Spamscanner: mailbox10.ucsd.edu  (v1.5 Aug 25 2004 09:28:35, -2.8/5.0 3.0.0)
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Orig-Path: decadentplace.org.uk!nobody
X-Newsgroups: comp.std.c++
X-MailScanner: PASSED (v1.2.8 78304 i9J90Hop078516 mailbox10.ucsd.edu)
Xref: g2news1.google.com comp.std.c++:3112

"John Max Skaller" wrote:
> On Mon, 18 Oct 2004 11:35:01 -0600, Ben Hutchings wrote:
> 
>> "John Max Skaller" wrote:
> 
>>> union U2 { int b; float a; U1() : a(1.0), b(1); } y;
>>> y.a; // 1.0f, well defined
> 
>> The standard says in 12.6.2/3:
>> 
>>    "If a ctor-initializer specifies more than one mem-initializer for
>>     the same member, for the same base class or for multiple members
>>     of the same union (including members of anonymous unions), the
>>     ctor-initializer is ill-formed."
> 
> Ah, thanks. Pity you can put non-POD types in unions then,
> I need to do that.. is there a proposal for a template like
> 
> 	store_of<T> 
> 
> which has the alignment and size of T and which can be
> used in a union, for all value types T?

No, but the Type Traits part of TR1 includes information about the
required alignments (std::tr1::alignment_of<T>).

> If I had one of those, it might do as a poor man's
> replacement for unions of arbitrary types, the lack of which is
> a fairly serious defect.

Boost.Variant <http://www.boost.org/libs/variant/> can do that for
you.

-- 
Ben Hutchings
The world is coming to an end.	Please log off.

---
[ 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                       ]



