Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created March 15, 2026 10:53
Show Gist options
  • Select an option

  • Save thinkphp/86252477270541a5f0978e23b36ee788 to your computer and use it in GitHub Desktop.

Select an option

Save thinkphp/86252477270541a5f0978e23b36ee788 to your computer and use it in GitHub Desktop.
template.cpp
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
// template<typename T> spune compilatorului T este un tip necunoscut, il deduci din apel
template<typename T>
T maxim(T a,T b) {
return (a > b) ? a : b;
}
template<typename T>
void sorteaza(vector<T>& v) {
sort(v.begin(), v.end());
}
template<typename T>
void afiseaza(const vector<T> &v, const string& sep = " "){
for(const auto& x: v) {
cout<<x << sep;
}
cout<<endl;
}
int main(int argc, char const *argv[])
{
cout<<maxim(3,7)<<endl;
cout<<maxim(3.14,2.71)<<endl;
cout<<maxim(string("Ana"), string("Maria"));
vector<int> note = {8,10,5,7,9};
sorteaza( note );
afiseaza( note );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment