| Thread overview | ||||||
|---|---|---|---|---|---|---|
|
June 13, 2017 How to check whether a struct is templated? | ||||
|---|---|---|---|---|
| ||||
Hi,
I loop through a structure during compile time and want to check whether a field of the structure is of type Nullable.
Therefore I use the TemplateOf traits which works for Nullable fields but raises an error for fields which are structures and not templated.
static if(is(T == struct) && __traits(isSame, TemplateOf!T, Nullable)){}
>> template std.traits.TemplateOf does not match any template declaration
I can not find a traits "isTemplateOf". Is there are workaround?
Kind regards
André
| ||||
June 13, 2017 Re: How to check whether a struct is templated? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andre Pany | Are you looking for something like this?
import std.typecons;
import std.traits;
alias yes = Nullable!int;
struct no {}
template isNullable(T : Nullable!X, X)
{
enum isNullable = true;
}
template isNullable(T)
{
enum isNullable = false;
}
void main()
{
static assert(isNullable!yes);
static assert(!isNullable!no);
}
| |||
June 13, 2017 Re: How to check whether a struct is templated? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andre Pany | On 06/13/2017 02:00 AM, Andre Pany wrote: > I can not find a traits "isTemplateOf". You're close. :) https://dlang.org/phobos/std_traits.html#isInstanceOf Ali | |||
June 13, 2017 Re: How to check whether a struct is templated? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On Tuesday, 13 June 2017 at 09:18:47 UTC, Ali Çehreli wrote:
> On 06/13/2017 02:00 AM, Andre Pany wrote:
>
>> I can not find a traits "isTemplateOf".
>
> You're close. :)
>
> https://dlang.org/phobos/std_traits.html#isInstanceOf
>
> Ali
Thanks :)
Kind regards
André
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply