Advertisement
bogolyubskiyalexey

Untitled

Jan 26th, 2021
938
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <random>
  5.  
  6. bool WrongCompare(int a, int b) {
  7.     return a <= b; // UB
  8. }
  9.  
  10. void f(std::mt19937& gen) {
  11.     std::uniform_int_distribution<> uid(0, 10);
  12.     std::vector<int> items(30);
  13.  
  14.     std::cout << "input: ";
  15.     for (auto& value : items) {
  16.         value = uid(gen);
  17.         std::cout << value << " ";
  18.     }
  19.     std::cout << std::endl;
  20.  
  21.     sort(items.begin(), items.end(), WrongCompare);
  22.  
  23.     std::cout << "result: ";
  24.     for (const int x : items) {
  25.         std::cout << x << " ";
  26.     }
  27.     std::cout << std::endl;
  28. }
  29.  
  30. int f(int x);
  31.  
  32. int g() {
  33.     return f(1);
  34. }
  35.  
  36. std::vector<int> z() {
  37.     return {};
  38.  
  39.     return std::vector<int>();
  40.  
  41. }
  42.  
  43.  
  44. std::pair<int, double> func() {
  45.     return {1, 3.14};
  46.     return std::make_pair(1, 3.14);
  47.     return std::pair<int, double>(1, 3.14);
  48. }
  49.  
  50. std::tuple<int, char, double> func2() {
  51.     std::tuple<int, char, double> z(1, 'a', 3.14);
  52.     std::get<0>(z) = 10;
  53.     return z;
  54. }
  55.  
  56. struct Type {
  57.     double y;
  58.     int z;
  59. };
  60.  
  61. Type func3() {
  62.     return Type{1, 3.14};
  63. }
  64.  
  65. std::vector<int> func4() {
  66.     return {1,2,3,4};
  67. }
  68.  
  69. int main() {
  70.    
  71.     auto [x, y] = func();
  72.     auto [q, w, y] = func2();
  73.     auto [p, z] = func3();
  74.     //auto [a1,a2,a3,a4] = func4(); CE
  75.  
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement