【发布时间】:2020-02-29 02:03:58
【问题描述】:
我想将我的“WorldChunk”类函数“getX()”和“getY()”与传递给函数的“chunk_x”和“chunk_y”进行比较,但我不想创建“WorldChunk”的新实例比较。
我尝试过类似的方法,但它不起作用。
int ChunkGrid::unload_chunk(unsigned int chunk_x, unsigned int chunk_y)
{
auto chunk = std::lower_bound(loaded_chunks.begin(), loaded_chunks.end(), NULL,
[chunk_x, chunk_y](const WorldChunk& ch, const auto * null)
{
return (ch.getX() == chunk_x && ch.getY() == chunk_y) ? true : false;
});;
//rest of the function
}
错误日志:
Error C2672 'operator __surrogate_func': no matching overloaded function found.
Error C2784 'auto ChunkGrid::unload_chunk::<lambda_d0b216222e2c66d42cf1e3316f6d68ac>::operator ()(const WorldChunk &,const _T1 *) const': could not deduce template argument for 'const _T1 *' from 'const _Ty'
【问题讨论】:
-
“如何使用 std::lower_bound 在没有第二个对象的情况下比较对象变量” - 你不能。不可能。寻找不同的方式。
-
您可能需要重新阅读有关 std::lower_bound() 的文档。听起来它与您尝试做的事情无关。到底你到底想完成什么?
-
我正在尝试将 WorldChunk x 和 y 与传入的函数进行比较,它是已排序的向量,因此我想使用 std::lower_bound 以获得更好的性能。
-
@Zmiennocieplny:它是按照 X 和 Y 排序的吗?按那个顺序?
标签: c++ sorting lambda std predicate