I'd use
std::optional if writing a custom find/findindex, assuming latest C++ standard. Makes the type system force the developer to handle the not found case whilst also acting as documentation that it can return nothing in the type system, which is the best place for such documentation
I also try and avoid break when possible. The vast majority of the time, if you need to break out of a for-loop then the code belongs in it's own function and you can then return out of the entire function. No stateful variable retvalue shenanigans needed.
As for the idea of a different result for an empty array, searching an empty array and finding nothing and searching a full array and finding nothing are equivalent operations, to my mind, so I'd have both return the same thing: None.
It's not the responsibility of a find function to care about the length of the array it receives, and having to handle more than "found" or "not found" complicates all of the calling code despite often searching an empty array actually being a valid operation, especially if your find is chained after other operations that could have filtered data out of the array beforehand.
I'd argue you stand a chance of catching developers out in a far more obtuse and hard to reason about way by the result of a find on an empty array being different from on a populated array. The fear of someone making a specific mistake with a simple algorithmic find function should not be leaking extra complexity into the rest of the code base or complicate legitimate occurrences that can't be differentiated from inside the find by breaking the concept of an 'exists/doesn't exist' find in the first place.
Unintialised data raises a general exception because that is a potentially unrecoverable general exception, no need to add any extra checks over what should be a crashing error.
(Of course, in C++ in practice I'd most likely use one of the
find algorithms the standard library already contains, instead of rolling my own. Same as with
LINQ in C# or
streams in Java. It's actually pretty rare to need to care about the index when dealing with sets of data when using those kinds of algorithms).