下面的代码很高兴被GCC和Clang接受,-std=c++14但导致Visual Studio 2013出现编译错误.
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
auto increasing = [](int lhs, int rhs){return lhs < rhs;};
auto decreasing = [](int lhs, int rhs){return lhs > rhs;};
std::vector<int> v(0, 10);
bool increase = true;
std::sort(v.begin(), v.end(), increase ? increasing : decreasing);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
错误是:
main.cpp(11): error C2446: ':': no conversion from 'main::<lambda_0228ee097b83254cfd8aa5f4015a245b>' to 'main::<lambda_cb3b816d067baa9d4462132ee332363c>'
main.cpp(11): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot …