10 Jan
2023
10 Jan
'23
5:08 p.m.
Alexander Grund wrote:
See `std::map::try_emplace(k, argsā¦)`.
https://en.cppreference.com/w/cpp/container/map/try_emplace
Notes: Unlike insert or emplace, these functions do not move from rvalue arguments if the insertion does not happen.
Yes, however at the callsite you can clearly see the different semantics: "try_" That's much harder for a constructor. Although a well-named factory method might be a solution if this semantic is useful.
For a constructor example, see https://eel.is/c++draft/util.smartptr.shared.const#29.