Technique: Immediately-Invoked Function Expression for Metaprogramming


Resource history | v1 (current) | created by jjones

Details

Technique: Immediately-Invoked Function Expression for Metaprogramming

| created by jjones | Add resource "Technique: Immediately-Invoked Function Expression for Metaprogramming"
Title
Technique: Immediately-Invoked Function Expression for Metaprogramming
Type
Web
Created
no value
Description
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([] { ... } ())!
Link
https://foonathan.net/2020/10/iife-metaprogramming/
Identifier
no value

authors

This resource has no history of related authors.

resources

This resource has no history of related resources.