ranges:namespace==std::ranges;folk_info:@structtype={uid:u32;name:std::string;position:std::string;}projector_example:()={folks:std::vector=(:folk_info=(0,"Ana","dev"),:folk_info=(1,"Bob","devops"),:folk_info=(2,"Eve","ops"));who:="Eve";it:=std::ranges::find(folks,who,folk_info::name&);ifit!=folks.end(){std::println("Profile:");std::println(" UID: {}",it*.uid);std::println(" Name: {}",it*.name);std::println(" Position: {}",it*.position);std::println("");}}main:()={projector_example();n1:constint=3;n2:constint=5;v:std::array=(4,1,3,2);ifranges::find(v,n1)!=v.end(){std::println("v contains: {}",n1);}else{std::println("v does not contain: {}",n1);}ifranges::find(v.begin(),v.end(),n2)!=v.end(){std::println("v contains: {}",n2);}else{std::println("v does not contain: {}",n2);}is_even:=:(x:int)x%2==0;(result:=ranges::find_if(v.begin(),v.end(),is_even))ifresult!=v.end(){std::println("First even element in v: {}",result*);}else{std::println("No even elements in v");}(result:=ranges::find_if_not(v,is_even))ifresult!=v.end(){std::println("First odd element in v: {}",result*);}else{std::println("No odd elements in v");}divides_13:=:(x:int)x%13==0;(result:=ranges::find_if(v,divides_13))ifresult!=v.end(){std::println("First element divisible by 13 in v: {}",result*);}else{std::println("No elements in v are divisible by 13");}(result:=ranges::find_if_not(v.begin(),v.end(),divides_13))ifresult!=v.end(){std::println("First element indivisible by 13 in v: {}",result*);}else{std::println("All elements in v are divisible by 13");}nums:std::vector=(:std::complex<double>=(4,2));it:=ranges::find(nums,std::complex<double>(4,2));assert(it==nums.begin());}
Output
Profile:
UID: 2
Name: Eve
Position: ops
v contains: 3
v does not contain: 5
First even element in v: 4
First odd element in v: 1
No elements in v are divisible by 13
First element indivisible by 13 in v: 4