Advanced search


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

April 1, 2020, 8:03 a.m.
Dmitry Kozhinov

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

  • Result:40points,
  • Rating points-8
March 30, 2020, 12:47 p.m.

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

  • Result:60points,
  • Rating points-1
March 29, 2020, 12:14 p.m.

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

  • Result:71points,
  • Rating points1
Last comments
April 3, 2020, 8:06 a.m.
Konstantin Grudnitskiy

Я надеюсь вы уже разобрались в чем дело, но если вдруг нет, то проблема состоит в том, что вы пытаетесь запустить программу из интерпретатора питона. Файл это уже готова…
April 3, 2020, 6:18 a.m.
Konstantin Grudnitskiy

>>> text = 'hello world'>>> ' '.join(word for word in text.split()[:-1])'hello'>>> def remove_last_word(text):... return text and ' '.join(word for word in text.s…
March 27, 2020, 2:40 p.m.
Evgenij Legotskoj

Добрый день. В конце пятой статьи скачать можете.
March 27, 2020, 2:28 p.m.
mkdir _

Здравствуйте, а можно, пожалуйста, ссылку на целые исходники, если есть?
March 27, 2020, 4:36 a.m.
Evgenij Legotskoj

Скорее всего также, как и для установки всех остальных переменых в CMake, через использование set
Now discuss on the forum
April 3, 2020, 12:53 p.m.

Само собою на компе этого незаметно.
April 3, 2020, 8:48 a.m.

Евгений, добрый день. Спасибо!
April 3, 2020, 7:52 a.m.

да вроде много чего установленно, если неправильный путь указать то же самое, пробовал запустить видео через плей лист (по примерам из док)и из него назад путь взять, не получилось
April 3, 2020, 5:50 a.m.

Спасибо ! Поковырявшись и посмотрев интерфейс QSvgRender и т.д. понимаю что похоже нужно будет лезть в реализацию ::render(..). Кто может подсказать как и где выкачать актуальные исходники…
April 2, 2020, 2:46 a.m.
Evgenij Legotskoj

Я думаю, что это где-то описано, но в такой глубине документации и максимум в самых базовых вещах, то есть отдельно в классах этого не пишут, просто потому, что придётся писать для каждого класс…
© EVILEG 2015-2019
Recommend hosting TIMEWEB