digitalmars.D.learn - how to check if an element is in array

• seany (7/7) Nov 18 2013 Is there a built in function in D to check if an element is a
• Jacob Carlborg (4/11) Nov 18 2013 For single dimensional arrays there is std.algorithm.canFind.
• Andrea Fontana (4/11) Nov 18 2013 If I'm right, canFind iterate over the range. If your array is
"seany" <seany uni-bonn.de> writes:
```Is there a built in function in D to check if an element is a
member of a (possibly multidimensional array?

say function(array, element). that returns to, if the element is
in the array, (or even better, if the elements of the array are
arrays themselves, then recursively checks if element is a
memeber of one of those arrays, and also reports the parent
array, of which element directly is a member of) ?
```
Nov 18 2013
Jacob Carlborg <doob me.com> writes:
```On 2013-11-18 16:33, seany wrote:
Is there a built in function in D to check if an element is a member of
a (possibly multidimensional array?

say function(array, element). that returns to, if the element is in the
array, (or even better, if the elements of the array are arrays
themselves, then recursively checks if element is a memeber of one of
those arrays, and also reports the parent array, of which element
directly is a member of) ?

For single dimensional arrays there is std.algorithm.canFind.

--
/Jacob Carlborg
```
Nov 18 2013
"Andrea Fontana" <nospam example.com> writes:
```On Monday, 18 November 2013 at 15:33:22 UTC, seany wrote:
Is there a built in function in D to check if an element is a
member of a (possibly multidimensional array?

say function(array, element). that returns to, if the element
is in the array, (or even better, if the elements of the array
are arrays themselves, then recursively checks if element is a
memeber of one of those arrays, and also reports the parent
array, of which element directly is a member of) ?

If I'm right, canFind iterate over the range. If your array is
sorted, you can try this:

http://dpaste.dzfl.pl/dfa24b9e
```
Nov 18 2013