函数模板的琐碎笔记

#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<set>
#include<queue>
#include<unordered_map>
#include<cmath>
using namespace std;
template<class T,class Pred>
void Map(T s, T e, T x, Pred op)
{
	for (; s != e; ++s, ++x)
		*x = op(*s);
}
int cube(int x) { return x * x * x; };
double square(int x) { return x * x; };
int main()
{
	int a[5] = { 1,2,3,4,5 }, b[5];
	Map(a, a + 5, b, cube);
	for (auto it : b)
		cout << it << " ";
}
#include<iostream>
#include<vector>
using namespace std;
template<class T1,class T2>
class Pair
{
public:
	T1 key;
	T2 value;
	pair(int _key, int _value) :key(_key), value(_value) {};
	bool operator<(const Pair<T1, T2>& a);
};
template<class T1, class T2>
bool Pair<T1, T2>::operator<(const Pair<T1, T2>& a)
{
	return key < a.key;
}
posted @ 2020-08-20 19:54  _Hsiung  阅读(47)  评论(0编辑  收藏  举报