MrS4g0

Untitled

Nov 13th, 2021 (edited)
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.     char a[] = "zdarova";
  6.     int b = 10;
  7.     uint64_t c = 1488;
  8.     long double d = 1337.228;
  9.     char e[] = "korova";
  10.     short f = 20;
  11.  
  12.  
  13.     vector<pair<char, void*>> st = {
  14.         { 'a', static_cast<void*>(&a) },
  15.         { 'b', static_cast<void*>(&b) },
  16.         { 'c', static_cast<void*>(&c) },
  17.         { 'd', static_cast<void*>(&d) },
  18.         { 'e', static_cast<void*>(&e) },
  19.         { 'f', static_cast<void*>(&f) }
  20.     };
  21.  
  22.     sort(st.begin(), st.end(),
  23.         [&](auto& a, auto& b) {
  24.             return a.second < b.second;
  25.         }
  26.     );
  27.  
  28.     for (auto& [first, second] : st) {
  29.         cout << first << " : " << second << '\n';
  30.     }
  31.  
  32.  
  33.     return 0;
  34. }
  35.  
  36. /*
  37. g++ -std=c++17 -O0
  38.  
  39. f : 0x52cedff4c6
  40. e : 0x52cedff4c9
  41. d : 0x52cedff4d0
  42. c : 0x52cedff4e8
  43. b : 0x52cedff4f4
  44. a : 0x52cedff4f8
  45.  
  46. g++ -std=c++17 -O2
  47. f : 0x1ecebffab2
  48. b : 0x1ecebffab4
  49. e : 0x1ecebffab9
  50. c : 0x1ecebffac0
  51. a : 0x1ecebffac8
  52. d : 0x1ecebffad0
  53. */
  54.  
  55.  
Add Comment
Please, Sign In to add comment