Technique: Immediately-Invoked Function Expression for Metaprogramming


Resource | v1 | created by jjones |
Type Web
Created unavailable
Identifier unavailable

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([] { ... } ())!

Relations

about Immediately invoked function expression

An immediately invoked function expression (or IIFE, pronounced "iffy") is a JavaScript programming l...

about Decltype

In the C++ programming language, decltype is a keyword used to query the type of an expression. Intro...


Edit details Edit relations Attach new author Attach new topic Attach new resource
0.0 /10
useless alright awesome
from 0 reviews
Write comment Rate resource Tip: Rating is anonymous unless you also write a comment.
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
Comments 0
Currently, there aren't any comments.