Project

General

Profile

Iterate through widgets

Added by Dominik Baláž almost 4 years ago

Hi,

recently i was trying to update wt-3 to wt-4 for my project. I am also using std::algorithm library for various tasks, for example finding widget based on some precondition:

auto it = std::find_if(con->children().begin(), con->children().end(), [&](auto w) { ... });

I have never faced this issue in version 3 but in version 4 it somehow broke and is now iterating beyond end causing SIGSEGV.

So, am i just using the library the wrong way or is there some reason why is this happening? What is the recommended way for given example (finding particular widget given precondition)?

D.


Replies (2)

RE: Iterate through widgets - Added by Roel Standaert almost 4 years ago

In Wt 3 children() would return a const reference. However, in Wt 4 it actually returns a value.

The result is that your begin() and end() are iterators of two different vectors. You will instead have to store the return value of children() and call begin() and end() on that.

RE: Iterate through widgets - Added by Dominik Baláž almost 4 years ago

I completely missed that. Thanks for your quick response! :)

D.

    (1-2/2)