嗨,我在排序之前将此代码用于我的商店索引,但是当我在此行中编译时: :
[&](size_t a, size_t b){ return values[a] < values[b]; }
,对我说错误:
Multiple markers at this line
- expected primary-expression before
'[' token
- expected primary-expression before
']' token
- expected primary-expression before
'a'
- expected primary-expression before
'b'
template <typename T>
std::vector<size_t> ordered(std::vector<T> const& values) {
std::vector<size_t> indices(values.size());
std::iota(indices.begin(), indices.end(), static_cast<size_t>(0));
std::sort(
indices.begin(), indices.end(),
[&](size_t a, size_t b){ return values[a] < values[b]; }
);
return indices;
}
第二个问题,当我有经典的输入一维数组时,我该如何调用?