digitalmars.D.learn - enum detection
- Jack Applegame (9/9) Nov 22 2012 How to detect enum member?
- Andrej Mitrovic (29/38) Nov 22 2012 That's not an enum, that's a manifest constant. This is an enum:
- bearophile (4/13) Nov 22 2012 Have you tried is(ident == enum) ?
- bearophile (3/4) Nov 22 2012 Sorry, ignore this answer, I was too much distracted.
- Kenji Hara (6/15) Nov 22 2012 Actual field might have `offsetof` builtin property.
- Jack Applegame (2/5) Nov 22 2012 Yes, it works! Thanks.
- Jack Applegame (2/5) Nov 22 2012 Yes, it works! Thanks.
How to detect enum member?
struct A {
enum id = 10;
int b;
char c;
}
foreach(ident; __traits(allMembers, A)) {
// is ident enum or not?
}
Nov 22 2012
On 11/22/12, Jack Applegame <japplegame gmail.com> wrote:
How to detect enum member?
struct A {
enum id = 10;
int b;
char c;
}
foreach(ident; __traits(allMembers, A)) {
// is ident enum or not?
}
That's not an enum, that's a manifest constant. This is an enum:
struct A {
enum id { x = 10 }
}
You can use:
struct A
{
enum id = 10;
int b;
char c;
}
template isEnum(alias symb)
{
static if (is(symb == enum))
enum bool isEnum = true;
else
enum bool isEnum = false;
}
void main()
{
foreach(ident; __traits(allMembers, A))
{
static if (isEnum!(__traits(getMember, A, ident)))
{
pragma(msg, ident, " yes");
}
}
}
Nov 22 2012
Jack Applegame:
How to detect enum member?
struct A {
enum id = 10;
int b;
char c;
}
foreach(ident; __traits(allMembers, A)) {
// is ident enum or not?
}
Have you tried is(ident == enum) ?
Bye,
bearophile
Nov 22 2012
Have you tried is(ident == enum) ?Sorry, ignore this answer, I was too much distracted. Bye, bearophile
Nov 22 2012
On Thursday, 22 November 2012 at 15:10:08 UTC, Jack Applegame
wrote:
How to detect enum member?
struct A {
enum id = 10;
int b;
char c;
}
foreach(ident; __traits(allMembers, A)) {
// is ident enum or not?
}
Actual field might have `offsetof` builtin property.
(not tested)
static if (is(typeof(mixin("A."~ident~".offsetof")))) {}
Kenji Hara
Nov 22 2012
On Thursday, 22 November 2012 at 17:36:03 UTC, Kenji Hara wrote:
Actual field might have `offsetof` builtin property.
(not tested)
static if (is(typeof(mixin("A."~ident~".offsetof")))) {}
Yes, it works! Thanks.
Nov 22 2012
On Thursday, 22 November 2012 at 17:36:03 UTC, Kenji Hara wrote:
Actual field might have `offsetof` builtin property.
(not tested)
static if (is(typeof(mixin("A."~ident~".offsetof")))) {}
Yes, it works! Thanks.
Nov 22 2012









Andrej Mitrovic <andrej.mitrovich gmail.com> 