如何测试是否找到了 boost::bimap “right.find” 的结果?

How do I test if the result from boost::bimap "right.find" was found or not?

提问人:Andrew Truckle 提问时间:12/22/2020 更新时间:12/22/2020 访问量:35

问:

我是使用新手,所以如果这听起来像是一个基本问题,请原谅我。我正在使用 boost 1.75.0。boost::bimap

以以下代码片段为例:

if (rBiMapStudentItemDescBefore.right.count(aryStrStudentItemDesc[i]) > 0)
{
    auto it = rBiMapStudentItemDescBefore.right.find(aryStrStudentItemDesc[i]);
    CString strNewStudentItemDesc = rBiMapStudentItemDescAfter.left.find(it->second)->second;
    pEntry->SetStudentAssignmentType(static_cast<StudentAssign>(i), strNewStudentItemDesc);
}

它工作正常。从文档或我发现的示例中,我不清楚是否可以取消调用并简单地测试如下所示的返回值:right.countit

if (it)
{

}

它不喜欢它。如何测试是否找到了结果?对不起,如果我在文档中错过了这一点。right.find

C++ Boost boost-bimap

评论


答:

-1赞 Andrew Truckle 12/22/2020 #1

我仍然找不到实际的文档,但我想我有它:

auto it = rBiMapStudentItemDescBefore.right.find(aryStrStudentItemDesc[i]);
if (it != rBiMapStudentItemDescBefore.right.end())
{
    CString strNewStudentItemDesc = rBiMapStudentItemDescAfter.left.find(it->second)->second;
    pEntry->SetStudentAssignmentType(static_cast<StudentAssign>(i), strNewStudentItemDesc);

}