Re: How do I pass a type as parameter in this method?

2017-12-19 Thread Marc via Digitalmars-d-learn
On Tuesday, 19 December 2017 at 15:52:57 UTC, Dgame wrote: On Tuesday, 19 December 2017 at 15:19:53 UTC, Marc wrote: [...] template FirstOf(T...) { template otherwise(D) { static if (T.length == 0) { enum otherwise = D.init; } else { enum otherwise

Re: How do I pass a type as parameter in this method?

2017-12-19 Thread Dgame via Digitalmars-d-learn
On Tuesday, 19 December 2017 at 15:19:53 UTC, Marc wrote: On Tuesday, 19 December 2017 at 00:01:00 UTC, Ali Çehreli wrote: On 12/18/2017 03:54 PM, Ali Çehreli wrote: On 12/18/2017 02:58 PM, Marc wrote: Here's another experiment: template FirstOf(T...) { template otherwise(D) {

Re: How do I pass a type as parameter in this method?

2017-12-19 Thread Marc via Digitalmars-d-learn
On Tuesday, 19 December 2017 at 00:01:00 UTC, Ali Çehreli wrote: On 12/18/2017 03:54 PM, Ali Çehreli wrote: On 12/18/2017 02:58 PM, Marc wrote: Here's another experiment: template FirstOf(T...) { template otherwise(D) { static if (T.length == 0) { enum otherwise =

Re: How do I pass a type as parameter in this method?

2017-12-18 Thread Ali Çehreli via Digitalmars-d-learn
On 12/18/2017 03:54 PM, Ali Çehreli wrote: On 12/18/2017 02:58 PM, Marc wrote: Here's another experiment: template FirstOf(T...) { template otherwise(D) { static if (T.length == 0) { enum otherwise = D.init; } else { enum otherwise = T[0]; }

Re: How do I pass a type as parameter in this method?

2017-12-18 Thread Ali Çehreli via Digitalmars-d-learn
On 12/18/2017 02:58 PM, Marc wrote: Imaginary code: int index = FirstOrDefault!(int)(__traits(getAttributes, C.a)); In that case, if the tuple is empty, the value is the int's type default value. The method is defined as  following: template FirstOrDefault(X)(T...) { static

How do I pass a type as parameter in this method?

2017-12-18 Thread Marc via Digitalmars-d-learn
Imaginary code: int index = FirstOrDefault!(int)(__traits(getAttributes, C.a)); In that case, if the tuple is empty, the value is the int's type default value. The method is defined as following: template FirstOrDefault(X)(T...) { static if(T.length > 0) { enum