www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Searching for Elements in Containers

reply =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= <per.nordlow gmail.com> writes:
Is there some function similar to std.algorithm.find() which 
returns an element index instead of a range? I guess 0 means no 
hit and 1, 2, 3 means hits at indexes 0, 1, 2 etc.

I want this to avoid having to create ranges ([]) when searching 
for a specific element in std.container.Array.
Feb 22 2015
parent "Tobias Pankrath" <tobias pankrath.net> writes:
On Sunday, 22 February 2015 at 13:53:51 UTC, Nordlöw wrote:
 Is there some function similar to std.algorithm.find() which 
 returns an element index instead of a range? I guess 0 means no 
 hit and 1, 2, 3 means hits at indexes 0, 1, 2 etc.

 I want this to avoid having to create ranges ([]) when 
 searching for a specific element in std.container.Array.
You could use a range and countUntil.
Feb 22 2015