CPP08 1.0
読み取り中…
検索中…
一致する文字列を見つけられません
easyfind.tpp
[詳解]
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* easyfind.tpp :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: kamitsui <kamitsui@student.42tokyo.jp> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2025/08/22 00:03:07 by kamitsui #+# #+# */
9/* Updated: 2025/08/22 00:15:48 by kamitsui ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13/**
14 * @file ex00/easyfind.tpp
15 */
16
17#ifndef EASYFIND_TPP
18#define EASYFIND_TPP
19
20#include "easyfind.hpp"
21
22template <typename T> typename T::iterator easyfind(T &container, int value) {
23 // Use the standard algorithm std::find to search for the value.
24 // std::find returns an iterator to the first occurrence of the value
25 // in the range [first, last).
26 typename T::iterator it = std::find(container.begin(), container.end(), value);
27
28 // If the returned iterator is equal to the container's end iterator,
29 // it means the value was not found.
30 if (it == container.end()) {
31 // In this case, throw our custom exception.
32 throw NotFoundException();
33 }
34
35 // Otherwise, return the iterator pointing to the found element.
36 return it;
37}
38
39#endif