| Thread overview |
|---|
October 04, 2017 How to implement `isTemplate` traits? | ||||
|---|---|---|---|---|
| ||||
I need to separate templates:
```
foreach(member; __traits(allMembers, V))
{
static if (__traits(compiles, { auto _val = &__traits(getMember, value, member); })
{
// a template needs to be instantiated to be addressable, so it works, but I think it's dirty hack instead of dry and clean way...
}
}
```
May be phobos has such traits somewhere?
| ||||
October 04, 2017 Re: How to implement `isTemplate` traits? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to drug | On Wednesday, 4 October 2017 at 09:32:31 UTC, drug wrote:
> I need to separate templates:
> ```
> foreach(member; __traits(allMembers, V))
> {
> static if (__traits(compiles, { auto _val = &__traits(getMember, value, member); })
> {
> // a template needs to be instantiated to be addressable, so it works, but I think it's dirty hack instead of dry and clean way...
> }
> }
> ```
> May be phobos has such traits somewhere?
template isTemplate(T...) if (T.length == 1) {
enum isTemplate = __traits(isTemplate, T[0]);
}
--
Biotronic
| |||
October 04, 2017 Re: How to implement `isTemplate` traits? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Biotronic | 04.10.2017 12:54, Biotronic пишет:
>
> template isTemplate(T...) if (T.length == 1) {
> enum isTemplate = __traits(isTemplate, T[0]);
> }
>
> --
> Biotronic
Thank you!
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply