std::string type("foo"); auto range = channel_widgets | filter([type](const std::shared_ptr<Widget> &w) { return w->getType() == type; }); if (range) { std::string target_widget = *range.begin(); std::cout << "widget found." << std::endl; } else { std::cerr << "widget not found" << std::endl; }