comp.lang.ada
 help / color / mirror / Atom feed
From: "Hyman Rosen" <hyman.rosen@gmail.com>
Subject: Re: Negative float problem
Date: 1 Nov 2005 08:04:31 -0800
Date: 2005-11-01T08:04:31-08:00	[thread overview]
Message-ID: <1130861070.985832.289890@g43g2000cwa.googlegroups.com> (raw)
In-Reply-To: <43677dec$1_1@glkas0286.greenlnk.net>

Martin Dowie wrote:
> Yup, you can't have overloaded enumeration values
> I guess because they are really just 'int', so which
> one would you mean?

No, that's not why. Enumerators have the type of their
enumeration. But enumerators go into their enclosing
namespace or class, so having multiple ones causes name
conflicts. You can actually simulate Ada's approach in
C++ by hand, as I show below. You can probably reduce
the boilerplate even more by using the Boost preprocessor
library, and that would also let you automatically get
string versions of the enumerators like Ada has.

#include <iostream>
#include <ostream>

struct Color { enum E { Red, Blue }; typedef E (&e)(E); };
struct Traffic_Light { enum E { Green, Amber, Red }; typedef E (&e)(E);
};

#define EDEF(C,e) C::E e(C::E = C::e) { return C::e; }
EDEF(Color, Red)
EDEF(Color, Blue)
EDEF(Traffic_Light, Green)
EDEF(Traffic_Light, Amber)
EDEF(Traffic_Light, Red)

void f_c(Color::e v)
 { std::cout << "Color: " << v(Color::E()) << "\n"; }
void f_t(Traffic_Light::e v)
 { std::cout << "Traffic_Light: " << v(Traffic_Light::E()) << "\n"; }

// Notice there are two Reds defined at global scope with no conflict
// and that each function is called with the proper Red.
int main() { f_c(Red); f_t(Red); }




  reply	other threads:[~2005-11-01 16:04 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-26 18:32 Negative float problem Luke
2005-10-26 19:05 ` Samuel Tardieu
2005-10-26 20:42 ` Robert A Duff
2005-10-27  8:05   ` Robert I. Eachus
2005-10-27 14:48     ` Robert A Duff
2005-10-27 15:07       ` Maciej Sobczak
2005-10-27 15:47         ` Robert A Duff
2005-10-28  8:34           ` Maciej Sobczak
2005-10-29 23:39             ` Brian May
2005-10-30  9:11             ` Dmitry A. Kazakov
2005-10-31  9:46               ` Maciej Sobczak
2005-10-31 14:20                 ` Dmitry A. Kazakov
2005-11-01 11:06                   ` Maciej Sobczak
2005-11-01 14:06                     ` Robert A Duff
2005-11-01 14:46                       ` Martin Dowie
2005-11-01 16:04                         ` Hyman Rosen [this message]
2005-11-01 17:19                           ` Martin Dowie
2005-11-02  0:13                         ` Robert A Duff
2005-11-02  6:59                           ` Martin Dowie
2005-11-02 13:24                             ` Robert A Duff
2005-11-02 15:22                               ` Martin Dowie
2005-11-01 15:12                       ` Maciej Sobczak
2005-11-02  0:28                         ` Robert A Duff
2005-11-02  4:16                           ` Steve Whalen
2005-11-14  7:26                           ` Dave Thompson
2005-11-20  0:19                             ` Robert A Duff
2005-11-20 11:07                               ` Dmitry A. Kazakov
2005-11-01 14:27                     ` Dmitry A. Kazakov
2005-11-01 15:19                       ` Maciej Sobczak
2005-11-01 19:44                         ` Dmitry A. Kazakov
2005-11-02  9:04                           ` Maciej Sobczak
2005-11-02 11:17                             ` Dmitry A. Kazakov
2005-11-02 13:03                               ` Maciej Sobczak
2005-11-02 14:20                                 ` Jean-Pierre Rosen
2005-11-02 20:15                                   ` Jeffrey R. Carter
2005-11-03 13:06                                     ` Jean-Pierre Rosen
2005-11-03 18:32                                       ` Jeffrey R. Carter
2005-11-03  9:51                                   ` Maciej Sobczak
2005-11-03 13:20                                     ` Jean-Pierre Rosen
2005-11-03 15:02                                       ` Maciej Sobczak
2005-11-03 18:55                                         ` Frank J. Lhota
2005-11-04  9:32                                           ` Maciej Sobczak
2005-11-03 20:59                                     ` Simon Wright
2005-11-02 13:32                               ` Robert A Duff
2005-11-02 14:44                                 ` Dmitry A. Kazakov
2005-11-02 13:47                               ` Dmitry A. Kazakov
2005-10-27 18:33       ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox