Topic: add an implicit const char* literal() function member
Author: Francis ANDRE <francis.andre.kampbell@orange.fr>
Date: Mon, 13 Jul 2015 10:17:12 +0200
Raw View
Hi
I am proposing to add a implicit member function to the enum type or
enum class type whose purpose would be to return the literal used to
define each enumerated value. For example
enum class Color { red, blue, yellow};
Color color = Color::yellow;
cout << "color=" << color.literal() << endl;
would output
color=yellow
1/ the literal fonction could be produced automaticaly by the compiler:
const char* literal();
2/ it should be generated only if it is referenced in the user's code
3/ when the value of the enum type variable is out of the range of the
enumerated value, the returned string could be "???" since "???" is not
a acceptable name for a enumerated.
4/ It does not break any previous code
The main interest of this function is to ligthen the explicitation of
the encoding of an user's defined enum, specificaly when the enum has a
large number of values.
FA
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.