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([] { ... } ())!
Relations
about Immediately invoked function expression
An immediately invoked function expression (or IIFE, pronounced "iffy") is a JavaScript programming l...
Edit details Edit relations Attach new author Attach new topic Attach new resource
from 0 reviews
- Resource level 0.0 /10
- beginner intermediate advanced
- Resource clarity 0.0 /10
- hardly clear sometimes unclear perfectly clear
- Reviewer's background 0.0 /10
- none basics intermediate advanced expert