Aug. 22, 2019, 3:42 a.m.


C++17, lambda, auto, functor

Developing the idea of caching the result of calculations of heavy functions , I propose to write a small template class, which will take the function as an argument, namely the lambda function, as the most universal an instrument within which a heavy function will be performed.

In this case, the result of the function will not be calculated at the time of creation of the Functor, but at the time of calling the operator parentheses () . And at the same time, the result will be cached. That will allow not to call a heavy function more than once as part of the execution of a method.

Aug. 21, 2019, 5:45 a.m.


lambda, auto, cache, C++14, C++

Suppose we wrote a function that calculates some value or uses a function to calculate this value, while the function_ which calculates the value is quite expensive to calculate and works for a long time. In this case, we call the lambda function several times in some code.

To avoid multiple calls to the heavy function, we can cache the value that the heavy function returns.

Aug. 21, 2019, 3:56 a.m.


C++, C++14, auto, lambda

Let's look at an interesting construction from the C++14 standard, which allows you to return the structure used in one place of the code, but you need to return an object with named fields.

Such a construction can serve as a replacement for std::tuple. At the same time, we will not need to declare any additional structures that we are not going to transfer anywhere, since we need to get only a set of data that we will somehow use immediately at the place of return and will not transfer further in the same form.

Aug. 6, 2018, 2:52 a.m.


template, lambda, C++11

The world of programming in C ++ in the new standards allows us to get up a variety of things, thanks to which we can safely abandon some old statements or principles, or simply flexibly approach these principles.

I would like to outline my view on the work of the RAII idiom and the C ++ 11 standard with respect to one established principle whose authorship is attributed to Edsger Dijkstra :

"The module (in this case the function) must have only one entry point and only one exit point"

For this principle, multiple returns in a function / method are contrary to the principles of structured programming for the following reasons:

  • the complexity of debugging code with the use of multiple returns returns increases with the number of these same return, that is, you never know when the function or method of an object just exited.
    the complexity of code support, when all the points of the call are not visible at the initial look at the function. Also, it is not known whether the code added to the end of the function will execute or not, especially if the program logic should always execute this code. That is, in the case of multiple returns, you will have to implement this code before every call to the return operator.

But modern C ++ has already changed significantly since the times of Dijkstra and the means of the latest C ++ standards allow to bypass or significantly level out the influence of the reasons that caused the formulation of the principles of structured programming.

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;
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

Jan. 27, 2020, 5:10 a.m.
Sergei Filin

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

  • Result:73points,
  • Rating points1
Jan. 25, 2020, 1:16 p.m.
Bekzod Muminov

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

  • Result:53points,
  • Rating points-4
Jan. 25, 2020, 1:04 p.m.
Bekzod Muminov

C ++ - Test 004. Pointers, Arrays and Loops

  • Result:20points,
  • Rating points-10
Last comments
Jan. 27, 2020, 9:53 a.m.

Единственная проблема состоит в том, что для выделения QCheckBox приходится дважны нажимать мышь. Получается что сначала выделяется ячейка. а только потом фокус уже попадает на виджет. …
Jan. 27, 2020, 1:01 a.m.
Ruslan Polupan

Да так, посмотрел библиотеку попробовал примеры...
Jan. 26, 2020, 2:51 p.m.

Чего не webassembly?
Jan. 21, 2020, 2:12 p.m.

Полезная статья. Как всегда - то что надо. Добавлю ещё маленькую полезность - после установки tracer (88 строка) и перед выводом значений в lineEdit (91 строка) стоит добавить updatePositio…
Jan. 17, 2020, 2:31 a.m.
Andrej Jankovich

Выглядит как ошибка библиотеки. Расскажите подробно на какой платформе вы собираете проект (MinGW или MSVC) их версии и версии Qt.
Now discuss on the forum
Jan. 27, 2020, 3:17 a.m.
Il'ja Chichak

а почему бы не сделать одну модель, например Attachement со всеми этими полями, и в зависимости от действия пользователя, например, "добавить документ", "добавить картинку" и т.д. класть все это…
Jan. 26, 2020, 11:42 a.m.

Другого способа, как получать перезагруженный контент через JavaScript на странице, я не знаю. Получилось сделать без QWebEngineView, с помощью QWebEnginePage, runJavaScrip…
Jan. 26, 2020, 11:14 a.m.

Да, я не понял до конца того, как это работает, мало опыта работы с qt и QVAriant ни разу не использовал. Спасибо за помощь)
Jan. 26, 2020, 4:11 a.m.
Vladimir Zhitkovsky

Да, спасибо порешалось таким образом: удаление одного for(int i = 0; i < lstData.count(); ++i){ auto *data= dynamic_cast<Data*>(lstData[i]); if(data) { if(…
Jan. 14, 2020, 9:04 a.m.
Ruslan Volshebnik

Проблема осталась. Но я выснил, что это происходит когда файл достигает максимального размера.
© EVILEG 2015-2019
Recommend hosting TIMEWEB