text: How do you initialize your variables, especially the const ones? What do you do when the code for the initialization is complicated? Do you move it to other method or just write inside the current scope?
  Intro
  I hope you’re initializing most of variables as const (so that the code is more verbose, explicit, and also compiler can reason better about the code and optimize). answer: you can wrap that initialization into a separate function.
  While that’s a right answer in most cases, I’ve noticed that in reality a lot of people just writes code in the current scope. That forces you to stop using
  const and code is a bit uglier. So we have something like:
  int myVariable = 0; if (bCondition) myVariable = bCond ? computeFunc(inputParam) : 0; else myVariable = inputParam * 2; // more code of the current function...
  I highly suggest wrapping such code into a separate method, but recently I’ve come across a new option.
  I’ve got it from a great talk by Jason Turner about “Practical Performance Practices” where among various tips I’ve noticed “IIFE”. This acronym stands for “Immediately-invoked function expression” and thanks to lambdas it’s now available in C++. We can use it for complex initialization of variables. How does it look like?
  IIFE
  The imaginary code from the previous section could be rewritten to:
  const int myVariable = [&] { if (bCondition) return bCond ? computeFunc(inputParam) : 0; else return inputParam * 2; }(); // more code of the current function...
  We’ve enclosed the original code with a lambda. It takes no parameters but captures the current scope by reference. Also look at the end of the code - there’s
  () - so we’re invoking the function immediately.
  Additionally, since this lambda takes no parameters, we can skip
  () in the declaration. Only
  [] is required at the beginning, since it’s the lambda-introducer .
  Would you use such thing in your code?
  I am a bit skeptical to such expression, but I probably need to get used to it. I wouldn’t use it for a long code. It’s probably better to wrap some long code into a separate method and give it a proper name. But if the code is 2 or three lines long… maybe why not.
  One note: regarding generated code you should get the same optimized code no matter if it’s IIFE or static function (or in an anonymous namespace). At least this is what Compiler Explorer is showing me. Basically, the code should be inlined. :)
  References
  - Herb Sutter Blog: Complex initialization for a const variable
  - C++ Weekly - Ep 32 - Lambdas For Free
  - Complex Object Initialization Optimization with IIFE in C++11 - from Jason Turner's Blog
  BTW: you can watch the whole Jason’s talk here:
  IIFE from ~10:20 (about using const)
  And here's another Jason's talk, solely about IIFE