0

I award 100 reputation to the person who can show me one sensible example of how a const && method-qualifier could be used in real world code which cannot be done more elegantly by using just const& or && overloads.

Nonsensible example

#include <cstdio>
#include <utility>


struct entity
{
    auto print() const&& {
        printf("Hello World!\n");
    }
};

int main()
{
    const entity e{};
    std::move(e).print();
}
glades
  • 3,778
  • 1
  • 12
  • 34
  • 1
    I don't think there's really a meaningful use case for. R-value references are intended for moving the contents of the referred object out of to somewhere else, but a const r-value reference thwarts this intention... – Aconcagua Feb 07 '23 at 11:38
  • 4
    From what I've seen, they are mostly use to `const&& = delete;` – Ted Lyngmo Feb 07 '23 at 11:53
  • Here's an example: https://godbolt.org/z/n95Gsb8aE – Ranoiaetep Feb 07 '23 at 11:53

0 Answers0