Thread overview | ||||||
---|---|---|---|---|---|---|
|
October 18, 2017 Trait to identify if a type is a struct one | ||||
---|---|---|---|---|
| ||||
Is there a way to identify if a type is a struct, something like isStruct similar to isArray. struct X { } isStruct!X == true? Also, there are isAbstractClass & isFinalClass but want to check if type is a class regardless? something like isClass? Thanks Pham |
October 18, 2017 Re: Trait to identify if a type is a struct one | ||||
---|---|---|---|---|
| ||||
Posted in reply to pham | 18.10.2017 18:11, pham пишет:
> Is there a way to identify if a type is a struct, something like isStruct
> similar to isArray.
>
> struct X
> {
> }
>
> isStruct!X == true?
>
> Also, there are isAbstractClass & isFinalClass but want to check if type is a class regardless? something like isClass?
>
> Thanks
> Pham
>
if (is(X == struct))
{
...
}
|
October 18, 2017 Re: Trait to identify if a type is a struct one | ||||
---|---|---|---|---|
| ||||
Posted in reply to drug | On Wednesday, 18 October 2017 at 15:16:21 UTC, drug wrote:
> 18.10.2017 18:11, pham пишет:
>> Is there a way to identify if a type is a struct, something like isStruct
>> similar to isArray.
>>
>> struct X
>> {
>> }
>>
>> isStruct!X == true?
>>
>> Also, there are isAbstractClass & isFinalClass but want to check if type is a class regardless? something like isClass?
>>
>> Thanks
>> Pham
>>
> if (is(X == struct))
> {
> ...
> }
static if (is(X == struct))
{
...
}
ptherwise lots of strnage errors ;)
|
October 18, 2017 Re: Trait to identify if a type is a struct one | ||||
---|---|---|---|---|
| ||||
Posted in reply to user1234 | On 10/18/2017 10:05 AM, user1234 wrote:
> On Wednesday, 18 October 2017 at 15:16:21 UTC, drug wrote:
>> 18.10.2017 18:11, pham пишет:
>>> Is there a way to identify if a type is a struct, something like isStruct
>>> similar to isArray.
>>>
>>> struct X
>>> {
>>> }
>>>
>>> isStruct!X == true?
>>>
>>> Also, there are isAbstractClass & isFinalClass but want to check if type is a class regardless? something like isClass?
>>>
>>> Thanks
>>> Pham
>>>
>> if (is(X == struct))
>> {
>> ...
>> }
>
> static if (is(X == struct))
> {
> ...
> }
>
> ptherwise lots of strnage errors ;)
>
Playing the devil's advocate, I think drug meant it as a function template constraint. :o)
void foo(X)(X x)
if (is(X == struct))
{
// ...
}
Ali
|
Copyright © 1999-2021 by the D Language Foundation