Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <stdexcept>
- std::int32_t findIndex(std::vector<std::int32_t>& v, std::int32_t x)
- {
- try
- {
- std::size_t = v.size();
- for ( std::size_t i = 0U; i < size; ++i)
- {
- if( v.at(i) == x)
- {
- throw i;
- }
- }
- }
- catch (std::size_t foundIdx)
- {
- return foundIdx;
- }
- catch(std::out_of_range& e)
- {
- return -1;
- }
- return -1;
- }
Add Comment
Please, Sign In to add comment