c模板编程c/c++20240401
c++模板编程
#include<iostream>
//#include<string>
//#include<algorithm>
template <typename T>
T max(T a, T b) {
return (a > b) ? a : b;
}
int main() {
int i = max(1, 2); // 返回 2
float f = max(3.14f, 2.72f); // 返回 3.14
std::string s = std::max(std::string("apple"), std::string("banana")); // 返回 "banana"
std::cout << i << std::endl;
std::cout << f << std::endl;
std::cout << s << std::endl;
}//main()
#include<iostream>
//#include<string>
//#include<algorithm>
#include<vector>
template <typename T>
T max(T a, T b) {
return (a > b) ? a : b;
}
typedef unsigned long long Ull;
std::vector<Ull> vec = { 2,3,4 };
int main() {
int i = max(1, 2); // 返回 2
float f = max(3.14f, 2.72f); // 返回 3.14
std::string s = std::max(std::string("apple"), std::string("banana")); // 返回 "banana"
std::cout << i << std::endl;
std::cout << f << std::endl;
std::cout << s << std::endl;
for (auto i : vec) {
std::cout << i << std::endl;
}//
for (Ull i = 0; true; ++i) {//for220
vec.emplace_back(i);
if ( 0 ==i % 100000000) {
Ull lastElement= vec.back();
std::cout << lastElement << ", ";
}
}//for220
}//main()
原文地址:https://blog.csdn.net/aw344/article/details/137255235
免责声明:本站文章内容转载自网络资源,如侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!