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); // 返回 2float f = max(3.14f, 2.72f); // 返回 3.14std::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) {//for220vec.emplace_back(i);if ( 0 ==i % 100000000) {Ull lastElement= vec.back();std::cout << lastElement << ", ";}}//for220}//main()