www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - enum, std.traits and "is(SomeEnumOfStruct == struct)" ?

reply "monarch_dodra" <monarchdodra gmail.com> writes:
I'm investigating a "inconsistent" behavior in std.traits 
regarding how the traits react when being passed an enum. To make 
things simple, they don't react the way you'd expect.

Consider the simple types:
//----
struct User
{
     char c;
     alias c this;
}

enum E_char : char {a = char.init}
enum E_User : User {a = User.init}
//----

Question: Which of these are aggregates? which of these are some 
char type?
Answer:
static assert(!isAggregateType!char);   //Makes sense
static assert( isAggregateType!User);   //Makes sense
static assert(!isAggregateType!E_char); //Makes sense
static assert(!isAggregateType!E_User); //[1] Makes no sense

static assert(  isSomeChar!char);   //Makes sense
static assert( !isSomeChar!User);   //Makes sense
static assert(  isSomeChar!E_char); //[2] Makes sense?
static assert(  isSomeChar!E_User); //[3] Makes no sense

As you can see, I think behaviors [1] and [3] simply make no 
sense. "[2]" is arguably up to debate.

In any case, I was wondering what the root issue was: Is it the 
implementation of std.trait or does it come from this behavior 
for "is", when enums are involved:

static assert ( is(User == struct));
static assert ( is(E_char == enum));
static assert ( is(E_User == enum));
static assert (!is(E_char == struct));
static assert (!is(E_User == struct)); //[HERE]

Question 1: Does the scenario [HERE] make sense? Is this correct 
behavior?

Question 2: Would the syntax: "is (T : struct)" or "is (T : 
enum)" make sense? It would work around the "problem" elegantly, 
as well as also provide support for asking things such as "does 
this class have an alias this to a struct", or "does this struct 
have an alias this to an enum"?
Sep 21 2013
parent "monarch_dodra" <monarchdodra gmail.com> writes:
On Saturday, 21 September 2013 at 16:08:23 UTC, monarch_dodra 
wrote:
 Question 2: Would the syntax: "is (T : struct)" or "is (T : 
 enum)" make sense? It would work around the "problem" 
 elegantly, as well as also provide support for asking things 
 such as "does this class have an alias this to a struct", or 
 "does this struct have an alias this to an enum"?
http://d.puremagic.com/issues/show_bug.cgi?id=11124
Sep 25 2013