c++ 函数模板
2016-06-29 15:41
441 查看
#include<iostream>
#include <list>
#include <vector>
using namespace std;
template<typename T>
int compare(const T &v1,const T &v2)
{
if(v1 < v2) return -1;
if(v1 > v2) return 1;
return 0;
}
template<typename T,typename U>
T find( T start, T end,const U &value)
{
while(start != end && *start != value)
start++;
return start;
}
template<typename T,unsigned N>
void print(const T (&arry)
)
{
for(unsigned i = 0;i != N;i++)
cout<<arry[i]<<endl;
}
template<typename T,size_t N>
T* begin(const T (&arry)
)
{
return &arry[0];
}
#include <list>
#include <vector>
using namespace std;
template<typename T>
int compare(const T &v1,const T &v2)
{
if(v1 < v2) return -1;
if(v1 > v2) return 1;
return 0;
}
template<typename T,typename U>
T find( T start, T end,const U &value)
{
while(start != end && *start != value)
start++;
return start;
}
template<typename T,unsigned N>
void print(const T (&arry)
)
{
for(unsigned i = 0;i != N;i++)
cout<<arry[i]<<endl;
}
template<typename T,size_t N>
T* begin(const T (&arry)
)
{
return &arry[0];
}
相关文章推荐
- 做题笔记
- 函数指针的简单用法
- c 单链表
- deep learning for face detection (caffe C++)
- C++动态识别与生成以及在MFC CRuntimeClass的应用
- AfxGetInstanceHandle()报错解决方法
- 利用tmp目录权限、suid 权限和C语言使普通帐号提权为ROOT权限
- C++中的C_str()函数用法
- 鞍点问题
- c++ assert() 归纳总结
- c++builder 中关于#pragma使用整理
- C++编写DLL并使用C++调用
- 程序员面试(c++)——预处理,const与sizeof总结
- #pragma 预处理指令详解
- 结构体和共同体
- zephir-流程控制语句
- c++成员函数做回调函数
- C语言的零长数组
- c++11 条件变量 std::condition_variable,多线程同步
- C++标准库和标准模板库