Hi,everyone,
It works maybe the best:
import std.stdio;
template isin(T){
bool isin(T[] Array,T Element){
foreach(T ArrayElement; Array){
if(Element==ArrayElement){ return true;}
}
return false;
}
}
void main(string[] args)
{
int[] stuff=[0,1,2,3,4,5
Hi,everyone,
This code must add the 'break',
import std.stdio;
int x=0;
template isin(T){
bool isin(T[] Array,T Element){
bool rtn=false;
foreach(T ArrayElement; Array){
if(Element==ArrayElement){
rtn=true; break; ← //here add break
On Mon, 21 Apr 2014 23:25:39 -0400, Taylor Hillegeist
wrote:
So I find myself Doing this kind of thing very frequently. I have a
Array of Somethings and i want to see if "something specific" is inside
the array. I wrote a template for it. but is this the best way to do
this kind of thing
On 04/21/2014 09:22 PM, Taylor Hillegeist wrote:
> Question though? why doesn't canFind() work on statically
> allocated arrays?
That's an issue all of face from time to time. (Happened to me again
last week. :) )
The reason is, algorithms like canFind work with input ranges and
fixed-length
On Tuesday, 22 April 2014 at 03:57:33 UTC, Timothee Cour via
Digitalmars-d-learn wrote:
you can use stuff.canFind(2)
but sometimes it'd be more convenient to have the other way
around (UFCS
chains etc);
how about:
bool isIn(T,T2...)(T needle, T2 haystack)
if(__traits(compiles,T.init==T2[0].i
you can use stuff.canFind(2)
but sometimes it'd be more convenient to have the other way around (UFCS
chains etc);
how about:
bool isIn(T,T2...)(T needle, T2 haystack)
if(__traits(compiles,T.init==T2[0].init)){
foreach(e;haystack){
if(needle==e) return true;
}
return false;
}
unittest{
So I find myself Doing this kind of thing very frequently. I have
a Array of Somethings and i want to see if "something specific"
is inside the array. I wrote a template for it. but is this the
best way to do this kind of thing. I feel like it doesn't help
with readability. Is there a better wa