--
Matthew
--
--- You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+unsubscribe@isocpp.org.
To post to this group, send email to std-dis...@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-discussion/.
--
Matthew
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussio...@isocpp.org.
I don't read the wording as that being valid. [namespace.udecl]/7 says "A using-declaration shall not name a scoped enumerator." [dcl.enum]/2 says " The enum-keys enum class and enum struct are semantically equivalent; an enumeration type declared with one of these is a scoped enumeration, and its enumerators are scoped enumerators. "
(From the DR) Should these rules be relaxed?
You'd need to repeat all the names previously declared in the enumerator-list, if this counts as a violation of Don't Repeat Yourself.. I guess you are out of luck.
enum class E { A, B, C };
...
using E::A;
using E::B;
using E::C;
E x = A;
Unless I hear it's a terrible idea, I think I will propose adding
'inline enum class' to the next revision of the standard. The effect
would be exactly as with 'inline namespace'; the contents of the named
scope are made accessible also via the parent scope. The other semantics
of 'enum class' would not be affected.
enum Purr : short;
inline enum Purr GetMood();
enum Purr : short
{
NONE,
WEAK,
STRONG,
};
inline Purr GetMood()
{
return Purr::NONE;
}
Why when inline enum is so much easier?
Because it breaks existing code. Linkage/storage class specifiers...whatever they're called...before "class C", "struct S", "enum E" are parsed as referring to what comes after it, not the type itself. This is why attributes go after the class keyword and such...I think. (Attributes before the class keyword would refer to the object being declared as that class type or to the function being declared.)
enum Purr : short;
inline enum Purr GetMood();
enum Purr : short
{
NONE,
WEAK,
STRONG,
};
inline Purr GetMood()
{
return Purr::NONE;
}
An inline enum would have to use the awkward syntax "enum inline E".
// Make no assumption about inline/class type.enum Purr : short;
inline Purr GetMood();
inline enum Purr : short
{
NONE,
WEAK,
STRONG,
};
inline Purr GetMood()
{
return Purr::NONE;
}
On Thursday 30 October 2014 20:05:07 gmis...@gmail.com wrote:
> > Unless I hear it's a terrible idea, I think I will propose adding
> > 'inline enum class' to the next revision of the standard. The effect
> > would be exactly as with 'inline namespace'; the contents of the named
> > scope are made accessible also via the parent scope. The other semantics
> > of 'enum class' would not be affected.
>
> I like this idea.
Maybe merge with the using namespace for classes option and just use the enum
to bring its identifiers into the scope.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussio...@isocpp.org.
On 2014-10-31 12:02, David Rodríguez Ibeas wrote:
> - Since 'enum' is not a 'namespace', just replace 'namespace' with 'enum':
> "using enum Enum;"
I also find "using namespace Enum"... strange. I'd prefer that over not
having the feature at all, but I definitely also prefer "using enum
Enum" over "using namespace Enum".
#define MACRO_ENUM_DEF(X,
Y) X,
#define MACRO_ENUM_REF(X,
Y) constexpr Y X = Y::X;
#define MACRO_ENUM_TO_STRING(X,
Y) case Y::X: return #Y "::" #X;
#define MACRO_DATA_OF_ENUM(FUNC, NAME) \
FUNC(A, NAME) \
FUNC(B, NAME) \
FUNC(C, NAME) \
FUNC(D, NAME) \
FUNC(E, NAME) \
FUNC(F, NAME) \
FUNC(G, NAME) \
FUNC(I, NAME) \
FUNC(NAME##_last, NAME)
enum EnumName
{
MACRO_DATA_OF_ENUM(MACRO_ENUM_DEF, EnumName)
};
MACRO_DATA_OF_ENUM(MACRO_ENUM_REF, EnumName)
inline std::string to_string(EnumName v
)
{
switch(v)
{
MACRO_DATA_OF_ENUM(MACRO_ENUM_
TO_STRING
, EnumName)
}
return "";
}
#undef MACRO_ENUM_DEF
#undef
MACRO_ENUM_REF
#undef
MACRO_ENUM_TO_STRING
#undef
MACRO_DATA_OF_ENUM
The above results in a compile-error when using `gcc` (`clang` accepts it), but it is valid according to the standard.You'd need to repeat all the names previously declared in the enumerator-list, if this counts as a violation of Don't Repeat Yourself.. I guess you are out of luck.
enum class E { A, B, C };
...
using E::A;
using E::B;
using E::C;
E x = A;
On Thu, Jan 2, 2014 at 6:05 PM, Matthew Woehlke <mw_t...@users.sourceforge.net> wrote:
Is there any way (that doesn't violate DRY) to make the values of a scoped enum (i.e. 'enum class') accessible to the parent scope, as with a traditional enum?
If not, would a method to do so be a reasonable addition to the standard?
--
Matthew
--
--- You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussio...@isocpp.org.