std::set 运算符不一致 <
std::set with unconsistent operator<
我正在编写 C++ 算法来解决棋盘游戏。
解决方案基于以下内容:
enqueue initial board
while queue not empty:
dequeue a board
if board is solved:
print solution
else:
for each possible board that can arise out of this one:
add board to end of queue
因为我不想检查同一块板不止一次,所以我使用 std::set<Board>
来跟踪检查过的板。
在Board
中定义classbool operator<(const Board& rhs) const
是为了让std::set
正常工作
那么,如果我的比较函数不能确保板实例中的顺序,那么在我的 std::set
中会发生什么情况?
例如:
a = Board()
b = Board()
c = Board()
a > b returns true
b > c returns true
a > c returns false
有没有可能std::set
,因为它是基于红黑树,多次插入同一个Board?
如果比较器不能正常工作,结构将无法正常工作。它可能会报告物品丢失。它可能无法插入某些东西。它可能会很快崩溃,或者它可能看起来适用于您的所有测试用例,然后在客户的机器上崩溃。
全部下注。
我正在编写 C++ 算法来解决棋盘游戏。 解决方案基于以下内容:
enqueue initial board
while queue not empty:
dequeue a board
if board is solved:
print solution
else:
for each possible board that can arise out of this one:
add board to end of queue
因为我不想检查同一块板不止一次,所以我使用 std::set<Board>
来跟踪检查过的板。
在Board
中定义classbool operator<(const Board& rhs) const
是为了让std::set
正常工作
那么,如果我的比较函数不能确保板实例中的顺序,那么在我的 std::set
中会发生什么情况?
例如:
a = Board()
b = Board()
c = Board()
a > b returns true
b > c returns true
a > c returns false
有没有可能std::set
,因为它是基于红黑树,多次插入同一个Board?
如果比较器不能正常工作,结构将无法正常工作。它可能会报告物品丢失。它可能无法插入某些东西。它可能会很快崩溃,或者它可能看起来适用于您的所有测试用例,然后在客户的机器上崩溃。
全部下注。