Is there a correlation between the lhs score of a member access operator and the side effects of its arguments?

I read the Grading Order from cppreference, but I could not find any rule that addresses this situation. Does this mean that there is no relationship with a consistent relationship, or am I missing something? Thank.

Below is a snippet of code.

#include <memory>

struct Foo {
  void func(std::unique_ptr<Foo>) {}
};

int main() {
  auto ptr = std::make_unique<Foo>();
  ptr->func(std::move(ptr)); // Is this valid?
  return 0;
}
+4
source share
1 answer

Previous C ++ 1z NO , do not write this.

Post C ++ 1z yes, from [expr.call]

A postfix expression is sequenced before each expression in the expression list and any default argument.

- ,

auto ptr_ = ptr.operator->();
auto func_ = &decltype(ptr)::element_type::func;
ptr_->*func_(std::move(ptr));

, , .

+6

Source: https://habr.com/ru/post/1681856/


All Articles