Daily bit(e) of C++ | Ref-qualified methods
Daily bit(e) of C++ #69, The C++11 ref-qualifiers for member functions With the introduction of r-value references, the C++11 standard also added ref-qualifiers for methods. This allows us to distinguish between situations when a method is invoked on an l-value and r-value object. If you dislike the resulting code duplication, look for the “deducing this” feature in C++23. struct MyClass {
    // mutable l-value
    void operation() & { }
    // prvalue or xvalue
    void operation() && { }
    // const l-value
    void operation() const& { }
};

const MyClass a;
a.operation();
// const l-value

MyClass b;
b.operation();
// mutable l-value

MyClass{}.operation();
// prvalue

std::move(b).operation();
// xvalue
Daily bit(e) of C++ | Ref-qualified methods Daily bit(e) of C++ #69, The C++11 ref-qualifiers for member functions With the introduction of r-value references, the C++11 standard also added ref-qualifiers for methods. This allows us to distinguish between situations when a method is invoked on an l-value and r-value object. If you dislike the resulting code duplication, look for the “deducing this” feature in C++23. struct MyClass {
    // mutable l-value
    void operation() & { }
    // prvalue or xvalue
    void operation() && { }
    // const l-value
    void operation() const& { }
};

const MyClass a;
a.operation();
// const l-value

MyClass b;
b.operation();
// mutable l-value

MyClass{}.operation();
// prvalue

std::move(b).operation();
// xvalue Software-Development
Daily bite C Refqualified method Daily bite C 69 C11 refqualifiers member function introduction rvalue reference C11 standard also added refqualifiers method allows u distinguish situation method invoked lvalue rvalue object dislike resulting code duplication look “deducing this” feature C23 struct MyClass mutable lvalue void operation prvalue xvalue void operation const lvalue void operation const const MyClass aoperation const lvalue MyClass b boperation mutable lvalue MyClassoperation prvalue stdmoveboperation xvalue SoftwareDevelopment