Как можно извлечь конструкцию объекта из заводской функции?C++

Программы на C++. Форум разработчиков
Anonymous
Как можно извлечь конструкцию объекта из заводской функции?

Сообщение Anonymous »

Можно ли извлечь конструкцию объекта из фабричной функции? < /p>

Код: Выделить всё

std::mutex f() {return std::mutex{};} // factory function using guarenteed copy elision allows this even though mutex cannot be copied or moved from

int main() {
std::optional m;
m.emplace(f()); // 

Подробнее здесь: [url]https://stackoverflow.com/questions/79692517/how-is-it-possible-to-emplace-construct-an-object-from-a-factory-function[/url]

Вернуться в «C++»