Advertisement
bogolyubskiyalexey

Untitled

Feb 5th, 2021
773
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. #include <algorithm>
  5.  
  6. template <class MyType>
  7. void print(const MyType& container) {
  8.     for (const auto& item : container) {
  9.         std::cout << item << " ";
  10.     }
  11.     std::cout << std::endl;
  12. }
  13.  
  14. template <class T, class G>
  15. void f(T a, G b) {
  16.     std::cout << a << " " << b << std::endl;
  17. }
  18.  
  19. template<class T>
  20. T create() {
  21.     return T();
  22. }
  23.  
  24. auto func(int z) {
  25.     if (z == 1) {
  26.         //return 1; error
  27.     }
  28.     return 1.0;
  29. }
  30.  
  31. /*
  32. template <class T>
  33. void myfunc(T<int> v) {
  34.     std::cout << v.size() << std::endl;
  35. }
  36. */
  37.  
  38.  
  39. int main() {
  40.     //std::vector<int> v;
  41.     //myfunc<std::vector>(v);
  42.  
  43.     f(1, 3.14);
  44.     f<char>(97, 3.14);
  45.     f<char, int>(98, 3.14);
  46.     std::vector<int> z = {1,2,3,100};
  47.     std::vector<double> d = {1.1,2,3.3,100};
  48.     std::set<char> s = {'q', 'z', 'a', 'r'};
  49.  
  50.     std::sort(z.begin(), z.end()); // 1, 2, 3, 100
  51.     std::sort(z.rbegin(), z.rend()); // 100, 3, 2, 1
  52.  
  53.     std::vector<int> qwe = {1,6, 7, 10, 2};
  54.     for (auto it = qwe.begin(); it != qwe.end(); ++it) {
  55.         std::cout << *it << std::endl;
  56.     }
  57.     for (auto it = qwe.rbegin(); it != qwe.rend(); ++it) {
  58.         std::cout << *it << std::endl;
  59.     }
  60.    
  61.     qwe.insert(qwe.end(), 10); //  {1,6, 7, 10, 2};
  62.  
  63.     /*std::vector<int>* ptr;
  64.     auto& myvector = *ptr;
  65.     myvector[2] = 10;
  66.     (*ptr)[2] = 4;
  67.     ptr->at(2) = 4;
  68.     int* data_ptr = qwe.data();*/
  69.  
  70.  
  71.  
  72.     double zz = func(1);
  73.     std::cout << zz << std::endl;
  74.     print(z);
  75.     print(d);
  76.     print(s);
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement