Topic: Question on using enumeration


Author: richard@ex-parrot.com ("Richard Smith")
Date: Sat, 28 Sep 2002 04:36:18 +0000 (UTC)
Raw View
"Hyman Rosen" <hyrosen@mail.com> wrote in message
news:1032459828.341148@master.nyc.kbcfp.com...
> Randy Maddox wrote:
>  > Could someone please explain the rationale behind this restriction?
>
> Uniformity? A using-declaration brings in a name.
> It doesn't bring in things that aren't the name.

However, there is a parallel with the using *directive* syntax which brings
in all of the names from some scope.  If a using directives for enums were
permitted, e.g.

    namespace ns
    {
      enum my_enum { foo, bar, baz };
    }
    using enum ns::my_enum;

    // foo, bar, baz and my_enum all now in scope.

this might provide a way of doing what you want.  ...Although not in the
current languange.

--
Richard Smith


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





Author: hyrosen@mail.com (Hyman Rosen)
Date: Mon, 23 Sep 2002 14:39:10 +0000 (UTC)
Raw View
Randy Maddox wrote:
> OTOH, using class_name::enum_type pulls in only the type name, which
> is pretty useless since I still cannot use any values of that type,
> without qualification.

Sure you can.

namespace A { enum E { one, two, three }; void foo(E) { } }
using A::E;
int main() { foo(E(2)); }

 > As it stands now, the two cases are not uniform

The using declaration makes a name available for use without
qualification. That is uniformity. Adding additional rules
that say that for certain names, a using declaration makes
certain other names also available without qualification is
not uniform.

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





Author: Hyman Rosen <hyrosen@mail.com>
Date: Thu, 19 Sep 2002 16:53:43 CST
Raw View
Randy Maddox wrote:
 > Could someone please explain the rationale behind this restriction?

Uniformity? A using-declaration brings in a name.
It doesn't bring in things that aren't the name.

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





Author: rmaddox@isicns.com (Randy Maddox)
Date: Sat, 21 Sep 2002 19:07:47 +0000 (UTC)
Raw View
Hyman Rosen <hyrosen@mail.com> wrote in message news:<1032459828.341148@master.nyc.kbcfp.com>...
> Randy Maddox wrote:
>  > Could someone please explain the rationale behind this restriction?
>
> Uniformity? A using-declaration brings in a name.
> It doesn't bring in things that aren't the name.
>

Well, yes, but that isn't very helpful here is it?

For example, using std::string pulls in the type string and lets me
use that type, and values of that type, without qualification.

OTOH, using class_name::enum_type pulls in only the type name, which
is pretty useless since I still cannot use any values of that type,
without qualification.

The difference is that enumeration values are names, but they are
still values too.

So you use the argument of uniformity, and I pass that argument right
back at you.  As it stands now, the two cases are not uniform in terms
of allowing the use of values of the type named in the using
declaration.

Randy.

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





Author: rmaddox@isicns.com (Randy Maddox)
Date: Thu, 19 Sep 2002 17:16:46 +0000 (UTC)
Raw View
Subclause 7.3.3 [namspace.udecl] paragraph 2 has a note explicitly
stating that "... specifying an enumeration name in a
using-declaration does not declare its enumerators ...".  Since the
main use of an enum is its enumerated values it seems this rather
limits the usefulness of an enum name in a using-declaration.  Could
someone please explain the rationale behind this restriction?

Thanks.

Randy.

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