CPP08/ex00/inc/easyfind.hpp

19 lines
342 B
C++

#pragma once
#include <algorithm>
#include <stdexcept>
template <typename T>
int &easyfind(T &container, int value)
{
typename T::iterator it = std::find(container.begin(), container.end(), value);
if (it != container.end())
{
return *it;
}
else
{
throw std::out_of_range("Value not found");
}
}