std::设置不一致的运算符<



我正在写一个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类中,定义bool 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,因为它是基于红黑树,插入相同的板不止一次?

如果比较器不能正常工作,则结构将不能正常工作。它可能会报告物品丢失。它可能无法插入一些东西。它可能很快崩溃,或者它可能在您的所有测试用例中工作,然后在客户的机器上崩溃。

最新更新