Closed tuanthien closed 4 months ago
Similar to the STL, if you make your constructors private for an immovable type, pre-17 you just need to make your constructors public or use some tag to prevent normal code calling them.
Post-17 you can have a friend helper function as copy elision is guaranteed.
My current workplace we use a lot of immovable objects within results and whilst awkward, it does work. We are C++ 20 however.
Does outcome have such helper function available? i couldn't find those functions to friend them in my immovable class. I feel like i misunderstanding something.
I'm saying that like with the STL, it's on you and your code to make it constructible by containing types if it is immovable.
For example, if you wanted to put an immovable type into std::pair<>
, the STL offers you an emplacement option and an assignment option. You need to figure out some technique best for your code to make use of the emplacement option.
I know you're looking to friend internal types to skip this issue, but neither the STL nor Boost nor Outcome would support you doing that.
I'm saying that like with the STL, it's on you and your code to make it constructible by containing types if it is immovable.
For example, if you wanted to put an immovable type into
std::pair<>
, the STL offers you an emplacement option and an assignment option. You need to figure out some technique best for your code to make use of the emplacement option.I know you're looking to friend internal types to skip this issue, but neither the STL nor Boost nor Outcome would support you doing that.
I see the actual problem now, thank you for spending time explain this to me. Happy lunar new year!
In case you haven't seen it; there is a small section in the documentation which covers this case: Result returning constructors
I have this setup where i need to in-place construct an immovable-type object but the constructor is private. I couldn't find any document about do this. I tried to friend a few suspicious internal classes, it but didn't work. Thank you.
I could make the constructor public and document it being internal but I curious if there is a better solution.
https://compiler-explorer.com/z/634o77aaz