Failure to use the stl vector instead of the [] operator

I have a method as follows (from the class, which implements the TBB task interface, but not currently multithreading) My problem is that two ways to access the vector cause completely different behavior - one works and the other makes the whole program explode quite spectacularly (this is a plugin, and usually the crash will depend on the host), but it takes outside the host program, as I said quite spectacularly)

void PtBranchAndBoundIterationOriginRunner::runOrigin(int origin, int time) const // NOTE: const method
{
    BOOST_FOREACH(int accessMode, m_props->GetAccessModes())
    {
        // get a const reference to appropriate vector from member variable
        // map<int, vector<double>> m_rowTotalsByAccessMode;
        const vector<double>& rowTotalsForAccessMode = m_rowTotalsByAccessMode.find(accessMode)->second;

        if (origin != 129) continue; // Additional debug constrain: I know that the vector only has one non-zero element at index 129

        m_job->Write("size: " + ToString(rowTotalsForAccessMode.size()));
        try {
            // check for early return... i.e. nothing to do for this origin 
            if (!rowTotalsForAccessMode[origin])    continue; // <- this works
            if (!rowTotalsForAccessMode.at(origin)) continue; // <- this crashes
        } catch (...) {
            m_job->Write("Caught an exception"); // but its not an exception
        }

        // do some other stuff
    }
}

I hate not to ask clearly defined questions, but at the moment my best phrase is "WTF?"

I am compiling this using Intel C ++ 11.0.074 [IA-32] using Microsoft (R) Visual Studio version 9.0.21022.8, and my implementation is vector

const_reference operator[](size_type _Pos) const
{   // subscript nonmutable sequence

#if _HAS_ITERATOR_DEBUGGING
    if (size() <= _Pos)
    {
        _DEBUG_ERROR("vector subscript out of range");
        _SCL_SECURE_OUT_OF_RANGE;
    }
#endif /* _HAS_ITERATOR_DEBUGGING */
    _SCL_SECURE_VALIDATE_RANGE(_Pos < size());

    return (*(_Myfirst + _Pos));
}

(Iterator debugging is off - I'm sure) and

const_reference at(size_type _Pos) const
{   // subscript nonmutable sequence with checking
    if (size() <= _Pos)
        _Xran();
    return (*(begin() + _Pos));
}

, , , , _Myfirst - ​​ ?

:

- 377, 129.

- , accessMode

, , @nikko:

map<int, vector<double>>::const_iterator it = m_rowTotalsByAccessMode.find(accessMode);
if (it != m_rowTotalsByAccessMode.end())
{
    ...

UPDATE 11.1.065, . , .

+3
3

, , , , . , Intel ++ , , , . 11.0.074, ; !

Intel, , - .

0

, , rowTotalsForAccessMode . , "m_rowTotalsByAccessMode.find(accessMode)" .

.find() (), ,

+3

( at) , ? :

  • rowTotalsForAccessMode
  • origin .
0
source

Source: https://habr.com/ru/post/1747156/


All Articles