Consider a simple C++ class that I do not want to modify:
class foo {};
Then if I do the following I will invoke the move assignment operator:
foo f{};
f = foo{};
Is there a way to invoke copy assignment without modifying foo
or using an intermediate g
like this:
foo f{};
foo g{};
f = g;
Almost as if there were std::dont_move
!
std::dont_move()
is easy to implement by yourself:
template <typename T>
const T& force_copy(T&& v)
{
return v;
}
See usage example
You can write:
f = static_cast<foo const&>(foo{});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With