aboutsummaryrefslogtreecommitdiff
path: root/cpp08/ex00/easyfind.hpp
blob: 7523f53cd3001e97d4f8f4427ed14aefd3a4469f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   easyfind.hpp                                       :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: charles <charles.cabergs@gmail.com>        +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/04/15 05:53:04 by charles           #+#    #+#             */
/*   Updated: 2020/12/15 11:58:54 by cacharle         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#ifndef EASYFIND_HPP
# define EASYFIND_HPP

# include <algorithm>

template<typename T>
int& easyfind(T& container, int x)
{
    typename T::iterator found = std::find(container.begin(), container.end(), x);
    if (found == container.end())
        throw std::exception();
    return *found;
}

#endif