CLion 2021.1 Help

Extract lambda parameter

The Extract Lambda Parameter refactoring helps you extract an expression or statement into a new parameter with a lambda expression passed as a corresponding argument. For example, this could be a comparator passed to a sorting function.

The following demo illustrates the usage of the Extract Lambda Parameter refactoring, as well as Extract Function, Extract Parameter, and Live Templates:

Extract a lambda parameter

  1. Select a code fragment you want to extract into a lambda parameter.

  2. Call Refactor | Extract/Introduce | Lambda Parameter from the main menu or choose Lambda Parameter from the Refactor This(Ctrl+Alt+Shift+T) popup:

    Extract Lambda Parameter option in Refactor This

  3. In the dialog that opens, specify the name, return type, and declaration placement for the new lambda parameter:

    The Extract Lambda Parameter dialog

  4. Review the changes in the Signature Preview field and press Extract. The refactoring with be applied right away:

    The result of Extract Lambda Parameter

Last modified: 12 March 2021