当前位置:网站首页>Variable parameter template implements max (accepts multiple parameters, two implementation methods)
Variable parameter template implements max (accepts multiple parameters, two implementation methods)
2022-06-24 11:34:00 【Junmo vv】
Imitative function implementation and recursive implementation
#include <iostream>
struct __Iter_less_iter
{
template<typename iteraotr1,typename iterator2>
bool operator() (iteraotr1 it1, iterator2 it2)
{
return *it1 < *it2;
}
};
__Iter_less_iter __iter_less_iter()
{
return __Iter_less_iter();
}
template<typename Iterator,typename comp>
Iterator __max_element(Iterator first, Iterator last, comp cmp)
{
if (first == last) {
return first;
}
Iterator reslut = first;
while (++first != last) { //last Is to point to the next position of the last element
if (cmp(reslut, first)) {
reslut = first;
}
}
return reslut;
}
template<typename T>
T max_element(T first,T last)
{
return __max_element(first, last, __iter_less_iter());
}
template <typename T>
T max(std::initializer_list<T> L)
{
return *max_element(L.begin(), L.end());
}
template <typename T>
T maxnum(T& in)
{
return in;
}
template <typename T,typename... Args>
T maxnum(T first, Args... args)
{
return std::max(first, maxnum(args...));
}
int main()
{
std::cout << max({ 23,42,44,22,11 }) << std::endl;
std::cout << maxnum( 23,42,44,22,11 ) << std::endl;
return 0;
}边栏推荐
- 美团基于 Flink 的实时数仓平台建设新进展
- ArrayList#subList这四个坑,一不小心就中招
- Maui's way of learning -- Opening
- 怎么申请打新债 开户是安全的吗
- GLOG从入门到入门
- How to export only the titles in word documents? (i.e. delete all the text contents and keep only the title) stop B
- 08. Tencent cloud IOT device side learning - device shadow and attributes
- Tencent geek challenge small - endless!
- 《opencv学习笔记》-- 图像的载入和保存
- 工具及方法 - 在Source Insight中使用代码格式化工具
猜你喜欢

程序员大部分时间不是写代码,而是。。。

把腾讯搬到云上,治愈了他们的技术焦虑

《opencv学习笔记》-- 图像的载入和保存

qt -- QTabWidget 中支持拖拽TabBar项

Today's sleep quality record 76 points

Beauty of script │ VBS introduction interactive practice

New progress in the construction of meituan's Flink based real-time data warehouse platform

@Requestbody annotation

齐次坐标的理解

美团基于 Flink 的实时数仓平台建设新进展
随机推荐
Why are some old SEO methods still effective?
哪个商业保险养老险好?2022年商业养老保险产品排名
≥ 2012r2 configure IIS FTP
如何优雅的写 Controller 层代码?
[深度学习][pytorch][原创]crnn在高版本pytorch上训练loss为nan解决办法
Déplacer Tencent sur le cloud a guéri leur anxiété technologique
Insurance app aging service evaluation analysis 2022 issue 06
Centripetalnet: more reasonable corner matching, improved cornernet | CVPR 2020 in many aspects
How to open a video number?
Today in history: Turing's birth day; The birth of the founder of the Internet; Reddit goes online
Visual presentation of pictures effectively enhances the attraction of large screen
2008R2 precautions for configuring L2TP pre shared key VPN
Internship experience sharing in ByteDance 𞓜 ten thousand word job guide
万名校园开发者花式玩AI,亮点看这张图就够啦!
New progress in the construction of meituan's Flink based real-time data warehouse platform
Use the process monitor tool to monitor process operations on registries and files
d的10个0符
H5 video conference, camera monitoring, web streaming and live broadcast integration scheme
math_ Summation and derivation of proportional series & derivation of sum and difference of equal powers / difference between two nth power numbers/
Which is a good CAD drawing software? How to select good software