- 论坛徽章:
- 0
|
- #include <iostream>
- #include <Pair.h>
- #include <Functional>
- #include <stdio.h>
- template <class _Pair>
- struct MySelect1st : public unary_function<_Pair, typename _Pair::first_type>
- {
- const typename _Pair::first_type& operator()(const _Pair& __x) const
- {
- return __x.first;
- }
- };
- int main()
- {
- pair<int, double> testPair(3, 10.0);
- MySelect1st< pair<int, double> > Select1stOperator;
- printf("%d\n", Select1stOperator(testPair));
- return 0;
- }
复制代码
为了不跟标准的重复定义,我把这个仿函数的名字改了一下,这个仿函数的作用就是重载operator()函数,从而在调用的时候传入一个pair得到这个pari的first成员 |
|