From 8494306507966301485
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,bf56a87b2f6d1e7f,start
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2004-02-08 16:10:17 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.icl.net!newsfeed.fjserv.net!kibo.news.demon.net!mutlu.news.demon.net!demon!mail2news.demon.co.uk!devnull
From: magfr@comp.std.cpp.magfr.user.lysator.liu.se (Magnus Fromreide)
Newsgroups: comp.std.c++
Subject: On strong types, literal values and such things
Date: Mon, 9 Feb 2004 00:10:12 +0000 (UTC)
Organization: Telia Internet
Lines: 61
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <87fzdl8apg.fsf@comp.std.cpp.magfr.user.lysator.liu.se>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: mail2news.demon.co.uk 1076285412 24984 10.0.0.1 (9 Feb 2004 00:10:12 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Mon, 9 Feb 2004 00:10:12 +0000 (UTC)
X-Received: from mulga.cs.mu.oz.au ([128.250.1.22])
	by news.demon.co.uk with esmtp (Exim 4.12)
	id 1Apz07-0006Up-00
	for mail2news@news.news.demon.net; Mon, 09 Feb 2004 00:10:12 +0000
X-Received: from mulga.cs.mu.OZ.AU (localhost [127.0.0.1]) by mulga.cs.mu.OZ.AU with ESMTP
	id i190A9i2028167; Mon, 9 Feb 2004 11:10:09 +1100 (EST)
X-Received: (from fjh@localhost)
	by mulga.cs.mu.OZ.AU (8.12.10+Sun/8.12.9/Submit) id i190A7dc028147;
	Mon, 9 Feb 2004 11:10:07 +1100 (EST)
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Path: comp-std-cpp-robomod!not-for-mail
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Delivered-To: std-c++@ucar.edu
X-Newsgroups: comp.std.c++
X-User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3
X-NNTP-Posting-Date: Sun, 08 Feb 2004 23:31:46 CET
X-Spam-Level: 
X-Spam-Checker-Version: SpamAssassin 2.60-mulga_r1 (1.212-2003-09-23-exp) on 
	mulga.cs.mu.OZ.AU
X-Spam-Status: No, hits=0.0 required=5.2 tests=none autolearn=no 
	version=2.60-mulga_r1
Xref: archiver1.google.com comp.std.c++:1067

Hello

I have read the proposals for strong typedefs as well as the one about
literal values and likes both but would like to se a little twist as
I think that the syntax with using is somewhat peculiar.

Why not use the only keyword that already adds a new type that is
incompatible with it's underlying type, that is enum.

With that we could get

typedef Classtype enum { } Newtype;

but since enums already have syntax of their own that would be equal to

Classtype enum Newtype { };

This also addresses the problem of how to add user supplied names to
constant values as follows:

Classtype enum {
        ClasstypedConstant = Classtype(4711)
};

Note that ClasstypedConstant is of an anonymous type but since enum values
lower to their base types it is assignable to a Classtype as well.

I do feel that it would be good if only literal values were allowed as right
hand sides in this kind of expression, especially if the proposal for widening
of the concept literal values is passed.

What would be the meaning of

Classtype enum { x };

One could argue that it should be a default constructed Classtype but then
the question is what

Classtype enum { x, y };

should give as value to y, x + 1? But what if Classtype lacks operator+
or even if it just isn't pure enough to give a literal value. I think
it would be best to avoid this can of worms by not defining the result
when the initializer is omitted.

This means that

int enum { x };

is undefined while

enum { x };

is well defined.

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



