Check template parameter whether it has "length"

2015-10-08 Thread tcak via Digitalmars-d-learn
I am "trying" to write a function that takes an array of items, and returns the length of longest item. [code] size_t maxLength(A)( const A[] listOfString ) if( __traits( hasMember, A, "length" ) ) { return 0; // not implemented yet } [/code] I tried it with if( __traits( compiles,

Re: Check template parameter whether it has "length"

2015-10-08 Thread John Colvin via Digitalmars-d-learn
On Thursday, 8 October 2015 at 09:29:30 UTC, tcak wrote: I am "trying" to write a function that takes an array of items, and returns the length of longest item. [code] size_t maxLength(A)( const A[] listOfString ) if( __traits( hasMember, A, "length" ) ) { return 0; // not

Re: Check template parameter whether it has "length"

2015-10-08 Thread Artur Skawina via Digitalmars-d-learn
On 10/08/15 11:29, tcak via Digitalmars-d-learn wrote: > I am "trying" to write a function that takes an array of items, and returns > the length of longest item. > > [code] > size_t maxLength(A)( const A[] listOfString ) if( __traits( hasMember, A, > "length" ) ) > { > return 0; // not

Re: Check template parameter whether it has "length"

2015-10-08 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 8 October 2015 at 09:29:30 UTC, tcak wrote: I am "trying" to write a function that takes an array of items, and returns the length of longest item. [code] size_t maxLength(A)( const A[] listOfString ) if( __traits( hasMember, A, "length" ) ) { return 0; // not

Re: Check template parameter whether it has "length"

2015-10-08 Thread tcak via Digitalmars-d-learn
On Thursday, 8 October 2015 at 09:50:12 UTC, John Colvin wrote: On Thursday, 8 October 2015 at 09:29:30 UTC, tcak wrote: [...] I'm 99% sure something like __traits(hasMember, int[], "length" ) should evaluate to true. Please file a bug at issues.dlang.org I notice it also doesn't work for

Re: Check template parameter whether it has "length"

2015-10-08 Thread John Colvin via Digitalmars-d-learn
On Thursday, 8 October 2015 at 15:22:02 UTC, tcak wrote: BTW, there is nothing like std.traits.hasLength. yeah, that's because __traits(hasMember, ...) should be good enough, but obviously not in this case at the moment.

Re: Check template parameter whether it has "length"

2015-10-08 Thread Meta via Digitalmars-d-learn
On Thursday, 8 October 2015 at 15:22:02 UTC, tcak wrote: BTW, there is nothing like std.traits.hasLength. You're just looking in the wrong place =) http://dlang.org/phobos/std_range_primitives.html#hasLength