Logo

Programming-Idioms

History of Idiom 222 > diff from v35 to v36

Edit summary for version 36 by Bryant:
New C++ implementation by user [Bryant]

Version 35

2022-10-14, 23:54:36

Version 36

2023-02-03, 08:20:16

Idiom #222 Find the first index of an element in list

Set i to the first index in list items at which the element x can be found, or -1 if items does not contain x.

Idiom #222 Find the first index of an element in list

Set i to the first index in list items at which the element x can be found, or -1 if items does not contain x.

Variables
i,x,items
Variables
i,x,items
Extra Keywords
position
Extra Keywords
position
Code
auto it = std::find(items.begin(), items.end(), x);
i = it == items.end() ? std::distance(items.begin(), it) : -1;