Quantcast
Browsing latest articles
Browse All 2 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 latest articles
Browse All 2 View Live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>