admin管理员组文章数量:1122832
I am using Visual Studio Code and CMake and GDB for my project. There is a bug in my code so I have to step through the code. Basically my class has a listener which is a lambda function. So I want to set break point where the listener calls and step into where actual lambda is. But there is a problem I have to step into multiple codes (which I think implementations of the lambda) which are unnecessary. Which make lose the track of the code, rather I want to directly jump to the my lambda.
Example:
#include <iostream>
#include <functional>
class Event {
public:
using Listener = std::function<void(const std::string&)>;
// Set the listener
void setListener(const Listener& listener) {
this->listener = listener;
}
// Trigger the event and notify the listener
void trigger(const std::string& message) const {
if (listener) {
listener(message);
}
}
private:
Listener listener;
};
// Example usage
int main() {
Event myEvent;
// Set the listener
myEvent.setListener([](const std::string& msg) {
std::cout << "Listener received: " << msg << '\n';
});
// Trigger the event
myEvent.trigger("Hello, listener!");
// Clear the listener and trigger again (no output expected)
myEvent.setListener(nullptr);
myEvent.trigger("This won't be received");
return 0;
}
If I add breakpoint here:
if (listener) {
本文标签:
Avoid library code when debugging c lambda functionStack Overflow
版权声明:本文标题:Avoid library code when debugging c++ lambda function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人,
转载请联系作者并注明出处:http://www.betaflare.com/web/1736282865a1926781.html,
本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论