如何将 STL 算法的 lambdas 绑定到 C 风格的多维数组?

How to bind lambdas for STL algorithms to C style multidimensional arrays?

我一直在尝试使用 STL 算法来处理多维数组的元素,但似乎没有任何东西绑定到它们。我该怎么做:

// Declaration of pix:
float pix[1000][2];

// (...)

const int sizeToParse = 300;
static auto colLessThan = [] 
    (const float coordPair_lhs[2], const float coordPair_rhs[2]) -> bool 
    // (const float** coordPair_lhs, const float** coordPair_rhs) -> bool 
    // (const float* coordPair_lhs[], const float* coordPair_rhs[]) -> bool 
{
    return coordPair_lhs[1] < coordPair_rhs[1]; 
};
float** lhsColMinIt;
float** lhsColMaxIt;
// float* lhsColMinIt[2];
// float* lhsColMaxIt[2];
std::tie(lhsColMinIt, lhsColMaxIt) = std::minmax_element(pix, pix + sizeToParse, colLessThan);

我的所有尝试都因编译器错误而被拒绝。

在接受答案后,它被简化为:

In instantiation of ‘std::tuple<_T1, _T2>& std::tuple<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) [with _U1 = const float ()[2]; _U2 = const float ()[2]; _T1 = float (&)[2]; _T2 = float (&)[2]]’:src/ClusterPairFunctions.cc:32:109: required from here /data/hunyadi/usr/include/c++/7.1.0/tuple:1252:25: error: invalid conversion from ‘const float () [2]’ to ‘float ()[2]’ [-fpermissive]

更新: 使用已接受的答案提供的方法,代码可以工作,我只是未能解决编译器在 std::tuple.

中报告 const 不正确的问题

在 C++14 中,在 lambda 中使用 const auto&

如果您必须明确提供类型:

static auto colLessThan = [] (const float (&lhs)[2], const float (&rhs)[2])
{
    return lhs[1] < rhs[1];
};

float (*lhsColMinIt)[2];
float (*lhsColMaxIt)[2];
std::tie(lhsColMinIt, lhsColMaxIt) =
    std::minmax_element(pix, pix + sizeToParse, colLessThan);

Demo