July 6, 2018, 4:26 a.m.


factorial, lambda, C++, лямбда функция, факториал

In the previous article , we got acquainted with the structure of lambda functions, and now we'll play with lambdas, calculate the factorial, and consider how the lambda function can be applied for this.

Let's consider for the beginning the usual variant of factorial calculation, and also we will specify that such a recursive function.

Recursive function

A recursive function is that function that calls itself. This means that inside the function there is a call to itself, and infinite recursion can occur if the function code does not have the conditions for exiting recursion.

Here is an example of such an infinite recursive function, the program with which it terminates crash due to overflow of the call stack.

#include <iostream>

using namespace std;

void infiniteRecursiveFunction()
    cout << "Hello World!" << endl;

int main()
    return 0;
Feb. 13, 2018, 6:13 p.m.


С++, лямбда функция

My favorite tool in C ++ is lambda functions, although somehow they told me that they seem scary. In fact they are lovely. They greatly simplify the writing of programs and allow you to make quite interesting decisions.

But before considering various ways of using lambda functions, I suggest to familiarize yourself with the basic syntax of lambda functions.

Possible options for the syntax of lambda functions

[ capture ] ( params ) mutable exception attribute -> ret { body }
[ capture ] ( params ) -> ret { body }
[ capture ] ( params ) { body }
[ capture ] { body }

The first option is complete, but it is not forbidden to use abbreviated variations in the recording of functions.

  • capture - list of external capture objects, they can be captured both by reference and by copying.
  • params - list of parameters passed to the lambda function, this part will be similar to writing arguments for normal functions.
  • mutable - Using mutable allows you to modify copies of objects that have been captured by copying. In the normal version, they will not be modified.
  • exception - provides an exception specification, that is, lambda functions as well as normal functions can throw exceptions.
  • attribute - provides an attribute specification, there are only two such attributes defined in the C ++ specification ([[noreturn]], [[carries_dependency]])
    • params - list of parameters passed to the lambda function
    • ret - the return value of the lambda function
Aug. 28, 2016, 11:17 a.m.


Qt, C++, lambda, QSignalMapper, лямбда функция

QSignalMapper is a wonderful class to organize the work of the signals and slots dynamically created objects. For example, the dynamically created buttons or objects in QStackedWidget. This was particularly true in older versions of the software, that is, and relied on Qt 4.8, which signals and slots system was based on the use of macros. But in the current realities of the new syntax in the indexes is much more convenient, and also supports a lambda function that can afford and does get rid of the application QSignalMapper, which will look like a monstrous throwback to new projects that use the latest version of the framework Qt and C++ language standards.

And when you consider more and congestion map() and mapped(), then it does with QSignalMapper code even more terrible, if used to connect signals and slots with the use of pointers, since it is necessary to cast the signals and slots, but more on that later.

Therefore, let us consider a small project that will be based on the example of the official documentation of Qt. Namely, an example will next. We have QLabel, QPushButton and Vertical Layout . By pressing a button in the Vertical Layout will be added to other dynamic buttons, by clicking on which QLabel will display the text from the button number in the following form: "Button 2". In the following figure shows an example of the application whose appearance will not differ, while the software implementations of the code will be a few.


Hello, Dear Users of EVILEG!!!

If the site helped you, then support the development of the site financially, please.

You can do it by following ways:

Thank you, Evgenii Legotckoi

Feb. 17, 2020, 2:41 p.m.

C++ - Тест 003. Условия и циклы

  • Result:85points,
  • Rating points6
Feb. 17, 2020, 6:02 a.m.

C++ - Test 006. Enumerations

  • Result:80points,
  • Rating points4
Feb. 17, 2020, 5:49 a.m.

C++ - Test 001. The first program and data types

  • Result:80points,
  • Rating points4
Last comments
Feb. 24, 2020, 12:37 a.m.

Евгений Здравствуйте! Не могу понять вот эту часть кода: url: jQuery(this).attr('action') наверное здесь должен быть путь к url, тогда 'action' на какой url указывает?
Feb. 17, 2020, 3:22 a.m.
Evgenij Legotskoj

Добрый день. Это кастомный тег, помещается в файл, который находится в каталоге templatetags myapp/ templatetags/ myapp.py
Feb. 16, 2020, 1:36 p.m.

Добрый вечер! Монжно по подробней о теге get_companion? ссылка не работает.
Feb. 16, 2020, 9:35 a.m.
Evgenij Legotskoj

Добрый день. На GitHub исходники, можете посмотреть в официальном репозитории
Now discuss on the forum
Feb. 23, 2020, 11:28 a.m.

Здравствуйте. Прошу совета с чего начать. Задание есть по лабе в универе: Напишите программу для чтения символов, где пользователь сможет выбрать любую точку клиентской области, щелкнув на ней …
Feb. 22, 2020, 1:05 p.m.

Всем привет. Для моей приложухи требуется доступ к хедерам дял чтения данных, но к ним имеет доступ рут, без него чтение не происходит. Но как я слышал можно вроде через dbus или polki…
Feb. 21, 2020, 5:19 a.m.
Vladimir Zhitkovsky

void sendImage(int sessid, int type, int dest, int format, QString imgBase64Data){ QNetworkRequest request; request.setUrl(QUrl(ipAddress + "ctlapi/cmd=preparereportimg&sessid=…
Feb. 20, 2020, 2:40 p.m.

Здравствуйте! Пишу игру - 2D платформер в среде Qt. Имею не очень много опыта в разработке. Подскажите, как можно реализовать ситуацию, где QGraphicScene больше, чем QGraphicView и надо двигать …
Feb. 20, 2020, 7:12 a.m.

Вот так похоже можно https://doc.qt.io/qt-5/qtpurchasing-index.html
© EVILEG 2015-2019
Recommend hosting TIMEWEB