Last active
May 14, 2020 17:00
-
-
Save Kiterai/9a1b64bfefadb11ba561876e75e65d11 to your computer and use it in GitHub Desktop.
64bitのUbuntuでppa:ubuntu-toolchain-r/testリポジトリからインストールしたGCC9.xで-O2にするとstd::sortの処理結果がおかしくなる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
struct A | |
{ | |
long long a, b; | |
}; | |
const int len = 10; | |
int main() | |
{ | |
A arr[len]; | |
for (int i = 0; i < len; i++) { | |
arr[i] = { rand() % 5, rand() % 5 }; | |
} | |
auto m = &A::b; | |
// expects sort by A::b | |
sort(arr, arr + len, | |
[m](A a, A b) { | |
return a.*m < b.*m; | |
}); | |
for (int i = 0; i < len; i++) { | |
cout << arr[i].a << ' ' << arr[i].b << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment