[SERVER-24299] Add template function in util/ that casts to std::unique_ptr<Derived> from std::unique_ptr<Base> Created: 26/May/16  Updated: 06/Dec/22  Resolved: 20/Aug/19

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: J Rassi Assignee: DO NOT USE - Backlog - Dev Tools
Resolution: Won't Do Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Developer Tools
Participants:

 Description   

A template function should exist in util/ that casts objects of type std::unique_ptr<Base> to std::unique_ptr<Derived>.

We could consider extending checked_cast for this purpose.



 Comments   
Comment by Andy Schwerin [ 08/Jun/16 ]

I wonder if such behavior would need to be aware of the second template argument of unique_ptr, the deleter, and if that would cause problems. If not, I'm a little surprised that this behavior wasn't provided for in the standard. Can you not provide overrides of static_cast via explicit conversion operators?

Generated at Thu Feb 08 04:05:56 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.