zoukankan      html  css  js  c++  java
  • 函数模板的琐碎笔记

    #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;
    }
    
  • 相关阅读:
    log日志----logging模块
    配置文件--configparser
    面向对象——进阶
    面向对象
    内置函数
    模块和包
    常用模块
    正则表达式
    递归函数
    内置函数+匿名函数
  • 原文地址:https://www.cnblogs.com/Hsiung123/p/13811939.html
Copyright © 2011-2022 走看看