🍌 C++ Feed
305 subscribers
218 photos
12.7K links
Агрегатор всего подряд про C++.

Для связи: @smertig

Powered by https://github.com/Smertig/banana
Download Telegram
Fluent C++
How to Implement operator= When a Data Member Is a Lambda

In C++, some types of class members make it tricky to implement a copy assignment operator, operator=. For example references, const members, and… lambdas. Indeed, in the majority of cases, lambdas don’t have an operator=. (In case you’re wondering in what case lambdas have an operator=, it is in C++20 and when they don’t capture anything.) […]
The post How to Implement operator= When a Data Member Is a Lambda appeared first on Fluent C++.
foonathan::blog()
Technique: Immediately-Invoked Function Expression for Metaprogramming

Common C++ guidelines are to initialize variables on use and to make variables const whenever possible.
But sometimes a variable is unchanged once initialized and the initialization is complex, like involving a loop.
Then an IIFE – immediately-invoked function expression – can be used: the variable is initialized by a lambda that computes the value, which is then immediately invoked to produce the value.
Then the variable is initialized on use and can also be made const.
I’ve been recently working on a meta-programming library where I found IIFEs useful in a slightly different context – computing type information.
TL;DR: decltype([] { ... } ())!