-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctional.hpp
82 lines (70 loc) · 2.09 KB
/
functional.hpp
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* functional.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aisraely <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/15 21:08:00 by aisraely #+# #+# */
/* Updated: 2022/01/15 21:08:00 by aisraely ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FUNCTIONAL_HPP
# define FUNCTIONAL_HPP
namespace ft
{
template <class Arg, class Result>
struct unary_function
{
typedef Arg argument_type;
typedef Result result_type;
};
template <class Arg1, class Arg2, class Result>
struct binary_function
{
typedef Arg1 first_argument_type;
typedef Arg2 second_argument_type;
typedef Result result_type;
};
template <class T>
struct equal_to : binary_function<T, T, bool>
{
bool operator() (const T &x, const T &y) const
{
return (x == y);
}
};
template <class T>
struct less : binary_function<T, T, bool>
{
bool operator() (const T &x, const T &y) const
{
return (x < y);
}
};
template <class Pair>
struct select_1st : public unary_function<Pair, typename Pair::first_type>
{
typename Pair::first_type &operator()(Pair &x) const
{
return (x.first);
}
const typename Pair::first_type &operator()(const Pair &x) const
{
return (x.first);
}
};
template <class T>
struct identity : public unary_function<T, T>
{
T &operator()(T &x) const
{
return (x);
}
const T &operator()(const T &x) const
{
return (x);
}
};
}
#endif