本文介绍了C ++在map中使用.find()和struct作为键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有我没有访问BOOST或STL我的结构和映射看起来类似于下面的伪装:

All I do not have access to BOOST or STL my struct and map looks similar to the following psuedo:

 

What I am trying to do is search my multimap for all cases where A = 2, B = 2, or A & B = 2. I am not exactly sure but, I think i need to create the predicates in my struct for "finding". Ideas?

推荐答案

运算符< $ c> find 或任何其他。但是,您的实现有一个错误。

operator< is all you need for find or anything else. However, your implementation has a bug. It returns true if the operands are equal.

找到 >和其他标准库组件使用假设 a == b iff! (a< b)&& ! (b ,因此如果 a 和 b 相等, c $ c>< 必须 false 才能使用 find 。 >

find and other Standard Library components use the assumption that a == b iff ! (a < b) && ! (b < a), so if a and b are equal, < must be false for find to work.

        else if (b == smk.b)
        {
            return false; // was true
        }

这篇关于C ++在map中使用.find()和struct作为键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 08:49
查看更多