forked from voutcn/megahit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctional.h
55 lines (46 loc) · 989 Bytes
/
functional.h
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
/**
* @file functional.h
* @brief Useful Functionals.
* @author Yu Peng
* @version 1.0.0
* @date 2011-08-24
*/
#ifndef __BASIC_FUNCTIONALS_H_
#define __BASIC_FUNCTIONALS_H_
#include <functional>
/**
* @brief It is a basic functional to return the input itself.
*
* @tparam T
*/
template <typename T>
struct Identity {
const T &operator ()(const T &value) const {
return value;
}
};
/**
* @brief It is a basic functional to select the first element of a stl pair.
*
* @tparam Pair
*/
template <typename Pair>
struct Select1st {
typedef typename Pair::first_type value_type;
const value_type &operator ()(const Pair &pair) const {
return pair.first;
}
};
/**
* @brief It is a basic functional to get the key value from a key-value pair.
*
* @tparam Key
* @tparam Value
*/
template <typename Key, typename Value>
struct GetKey {
const Key &operator ()(const Value &value) const {
return value.key();
}
};
#endif