std::vector<IMenu*> LayoutManager::findAllMenus(IWindow& window, const char* path) { // create a collection of all menus associated with this window. auto& windowMenus = window.menus(); std::vector<IMenu*> menus(windowMenus.size() + dynamicMenus_.size()); // copy all the menus owned by the window auto it = std::transform(windowMenus.begin(), windowMenus.end(), menus.begin(), [](const std::unique_ptr<IMenu>& menu) { return menu.get(); }); // copy all the menus dynamically registered for this window auto windowId = safe_str(window.id()); it = std::copy_if(dynamicMenus_.begin(), dynamicMenus_.end(), it, [&](IMenu* menu) { auto menuWindowId = safe_str(menu->windowId()); return strcmp(windowId, menuWindowId) == 0; }); // resize the collection to the actual number of menus that were collected menus.erase(it, menus.end()); for (auto it = menus.begin(); it != menus.end();) { if (matchMenu(**it, path)) { ++it; continue; } it = menus.erase(it); } return menus; }