I am struggling to understand the different behavior shown between move and an rvalue cast
given:
template <class T> void f1(T param) { }
struct B { B() = default; B(B&&) { cout << "Move constructor\n"; } };
void demo()
{
f1(static_cast<B&&>(B())); // does not call move constructor - constructor is elided
f1(move(B())); // calls move constructor - no elision
}
The move call forces the call to the move constructor, while the static cast does not, and the constructor is apparently elided. This seems strange as the definition of std::move looks very much like a static cast.
Why the different behavior?
Update: Cannot be reproduced with gcc. Behavior shown only with MSVC
move<B>
- The explicit argument is kinda idiosyncratic, just saying. It's meant to be about deducing the arguments – Perpetrate