Quantcast
Channel: Use std::atomic in lambda expression - Stack Overflow
Browsing all 2 articles
Browse latest View live

Answer by yuri kilochek for Use std::atomic in lambda expression

You can initialize the capture directly and rely on C++17 guaranteed copy/move elision:#include <atomic>int main(){ auto check = [a = std::atomic_int(42)]() mutable { return a.fetch_sub(1) == 1; };}

View Article


Use std::atomic in lambda expression

I want to capture a std::atomic in a lambda expression. The lifetime of the atomic variable must be tied to the lambda, so I cannot capture by reference, but I want to avoid heap allocation.How can I...

View Article
Browsing all 2 articles
Browse latest View live