Advertisement
RobertDeMilo

YB4.2 Концепция полуинтервалов итераторов

Nov 10th, 2023
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. //struct Lang
  8. //{
  9. //  string name;
  10. //  int age;
  11. //};
  12.  
  13. //void PrintRange(vector<string>::iterator range_begin, vector<string>::iterator range_end)
  14. //{
  15. //  for (auto it = range_begin; it != range_end; ++it)
  16. //  {
  17. //      cout << *it << " ";
  18. //  }
  19. //}
  20.  
  21. //using LangIt = vector<string>::iterator;
  22. //void PrintRange(LangIt range_begin, LangIt range_end)
  23. //{
  24. //  for (auto it = range_begin; it != range_end; ++it)
  25. //  {
  26. //      cout << *it << " ";
  27. //  }
  28. //}
  29.  
  30. template<typename It>
  31. void PrintRange(It range_begin, It range_end)
  32. {
  33.     for (auto it = range_begin; it != range_end; ++it)
  34.     {
  35.         cout << *it << " ";
  36.     }
  37. }
  38.  
  39. int main()
  40. {
  41.     vector<string> langs = { "Python", "C++", "C", "Java", "C#" };
  42.  
  43.     PrintRange(begin(langs), end(langs));
  44.     PrintRange(begin(langs[0]), end(langs[0]));
  45.  
  46.     //#######################################################################################################
  47.  
  48.     /*vector<Lang> langs = { {"Python", 26}, {"C++", 34}, {"C", 45}, {"Java", 22}, {"C#", 17} };
  49.     auto result = find_if(begin(langs), end(langs), [](const Lang& lang)
  50.             {return lang.name[0] == 'C'; });*/
  51.  
  52.     /*string lang = langs[1].name;
  53.     auto it = begin(lang);
  54.     cout << *it << endl;
  55.     ++it;
  56.     cout << *it << endl;*/
  57.  
  58.     // cout << end(langs)->name;  НЕЛЬЗЯ!
  59.  
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement