Thread overview |
---|
February 15, 2018 How to check if aggregate member is static templated method? | ||||
---|---|---|---|---|
| ||||
https://run.dlang.io/is/zHT2XZ |
February 15, 2018 Re: How to check if aggregate member is static templated method? | ||||
---|---|---|---|---|
| ||||
Posted in reply to drug | 15.02.2018 16:50, drug пишет:
> https://run.dlang.io/is/zHT2XZ
I can check againts if member is either static function or template. But I failed to check if it both static and templated.
|
February 15, 2018 Re: How to check if aggregate member is static templated method? | ||||
---|---|---|---|---|
| ||||
Posted in reply to drug | On Thursday, 15 February 2018 at 13:51:41 UTC, drug wrote: > 15.02.2018 16:50, drug пишет: >> https://run.dlang.io/is/zHT2XZ > I can check againts if member is either static function or template. But I failed to check if it both static and templated. The best I could come up with is: struct Foo { static staticMethod() { } static templatedStaticMethod(T)(T t) { } } void main() { static if(__traits(isTemplate, Foo.templatedStaticMethod) && __traits(isStaticFunction, Foo.templatedStaticMethod!int)) { writeln("win"); } } It seems like a templated method can be queried if it is static only after it's instantiation. Hope this helps. Cheers, RazvanN |
February 15, 2018 Re: How to check if aggregate member is static templated method? | ||||
---|---|---|---|---|
| ||||
Posted in reply to RazvanN | 15.02.2018 18:49, RazvanN пишет:
> On Thursday, 15 February 2018 at 13:51:41 UTC, drug wrote:
>> 15.02.2018 16:50, drug пишет:
>>> https://run.dlang.io/is/zHT2XZ
>> I can check againts if member is either static function or template. But I failed to check if it both static and templated.
>
> The best I could come up with is:
>
> struct Foo
> {
> static staticMethod()
> {
> }
>
> static templatedStaticMethod(T)(T t)
> {
> }
> }
>
> void main()
> {
> static if(__traits(isTemplate, Foo.templatedStaticMethod) &&
> __traits(isStaticFunction, Foo.templatedStaticMethod!int))
> {
> writeln("win");
> }
> }
>
> It seems like a templated method can be queried if it is static only after it's instantiation. Hope this helps.
>
> Cheers,
> RazvanN
Thank you for answer!
|
February 16, 2018 Re: How to check if aggregate member is static templated method? | ||||
---|---|---|---|---|
| ||||
Posted in reply to RazvanN | On Thursday, 15 February 2018 at 15:49:47 UTC, RazvanN wrote:
> On Thursday, 15 February 2018 at 13:51:41 UTC, drug wrote:
>> 15.02.2018 16:50, drug пишет:
>>> https://run.dlang.io/is/zHT2XZ
>> I can check againts if member is either static function or template. But I failed to check if it both static and templated.
>
> The best I could come up with is:
>
> struct Foo
> {
> static staticMethod()
> {
> }
>
> static templatedStaticMethod(T)(T t)
> {
> }
> }
>
> void main()
> {
> static if(__traits(isTemplate, Foo.templatedStaticMethod) &&
> __traits(isStaticFunction, Foo.templatedStaticMethod!int))
> {
> writeln("win");
> }
> }
>
> It seems like a templated method can be queried if it is static only after it's instantiation. Hope this helps.
>
> Cheers,
> RazvanN
I would kinda argue that it's a bug, because checking whether a template function is static can become very complex if the template also has constraints etc.
|
Copyright © 1999-2021 by the D Language Foundation