Advertisement
chevengur

СПРИНТ № 2 | Шаблоны функции | Урок 5: Универсальные функции вывода контейнеров 3/6

Oct 26th, 2023
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4.  
  5. using namespace std;
  6.  
  7. template<typename type>
  8. ostream& operator<< (ostream& out, const set<type>kunteynir){
  9.     bool first_ap = true;
  10.    
  11.     for(const auto& kun: kunteynir){
  12.         if(!first_ap){
  13.             out << ", ";
  14.         }
  15.         first_ap = false;
  16.         out << kun;  
  17.     }
  18.    
  19.     return out;
  20. }
  21.  
  22. template<typename type>
  23. ostream& operator<< (ostream& out, const vector<type>kunteynir){
  24.     bool first_ap = true;
  25.    
  26.     for(const auto& kun: kunteynir){
  27.         if(!first_ap){
  28.             out << ", ";
  29.         }
  30.         first_ap = false;
  31.         out << kun;  
  32.     }
  33.    
  34.     return out;
  35. }
  36.  
  37. int main() {
  38.     const vector<int> ages = {10, 5, 2, 12};
  39.     const set<int> set_ages = {20, 15, 3 , 1};
  40.     cout << ages << endl;
  41.     cout << set_ages << endl;
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement