Search code examples
c++debuggingvectorvisual-studio-2015conditional-breakpoint

Visual Studio 2015 breakpoint condition for two dimensional vector size


I have a two dimensional vector at which I want to break if the height does not equal the width.
I thought of a condition like this my_vector.size() != my_vector[0].size() but when I tried this I got the error "This expression has side effects and will not be evaluated".
I saw the answer to this question and tried to use _Mylast and _Myfirst but then I got the error "The breakpoint cannot be set. a pointer to a bound function may only be used to call the function".
What else can I do to get the size of a vector in a breakpoint condition?


Solution

  • Since the question hasn't received a more elaborate answer yet, I'll post my comment as an answer.

    Instead of trying to use a condition breakpoint, you can modify the source code, to call into the debugger itself:

    if (my_vector.size() != my_vector[0].size())
    {
        __debugbreak();
    }
    

    This is also useful for a tight loop, because a conditional breakpoint is very slow, whereas this technique has minimal overhead.