Will move constructor always take place in initialization statements that involve auto in C++?

Viewed 90

So currently I prefer this style of initializing an object in C++, for example:

auto t{ std::thread(hello) };

I don't know if there is any, even slightly, cost of executing here because according to my understanding, an anonymous object of type std::thread will be constructed first, then my local variable t will be move-constructed with that object. This means we have to perform 2 types of constructions to get my variable t ready.

Is this really true? If so, does the following style perform better?

std::thread t{ hello };   // only 1 constructor will be invoked

I am concerning with the standard of C++20.

0 Answers
Related