In this recipe, we will learn how to convert from a std::unique_ptr into a std::shared_ptr. This recipe is important as it is often convenient to define an API as accepting std::unique_ptr when the API itself really needs std::shared_ptr for internal use. A good example of this is when creating a GUI API. You might pass a widget to the API to store and own, without knowing if, later on down the road, the implementation of your GUI might need to add threads, in which case std::shared_pointer might be a better option. This recipe will provide you with the skills to convert a std::unique_ptr into a std::shared_ptr if needed, without having to modify the API itself.
United States
Great Britain
India
Germany
France
Canada
Russia
Spain
Brazil
Australia
Singapore
Hungary
Ukraine
Luxembourg
Estonia
Lithuania
South Korea
Turkey
Switzerland
Colombia
Taiwan
Chile
Norway
Ecuador
Indonesia
New Zealand
Cyprus
Denmark
Finland
Poland
Malta
Czechia
Austria
Sweden
Italy
Egypt
Belgium
Portugal
Slovenia
Ireland
Romania
Greece
Argentina
Netherlands
Bulgaria
Latvia
South Africa
Malaysia
Japan
Slovakia
Philippines
Mexico
Thailand