mirror of
https://github.com/AnthonyCalandra/modern-cpp-features.git
synced 2025-12-18 02:24:35 +03:00
Update README.md (#136)
* Update README.md * Update CPP17.md * Update CPP11.md * Improve the ref-qualified member functions code even more. --------- Co-authored-by: Anthony Calandra <anthony@anthony-calandra.com>
This commit is contained in:
18
CPP11.md
18
CPP11.md
@@ -619,23 +619,23 @@ struct Bar {
|
||||
};
|
||||
|
||||
struct Foo {
|
||||
Bar getBar() & { return bar; }
|
||||
Bar getBar() const& { return bar; }
|
||||
Bar getBar() && { return std::move(bar); }
|
||||
Bar& getBar() & { return bar; }
|
||||
const Bar& getBar() const& { return bar; }
|
||||
Bar&& getBar() && { return std::move(bar); }
|
||||
const Bar&& getBar() const&& { return std::move(bar); }
|
||||
private:
|
||||
Bar bar;
|
||||
};
|
||||
|
||||
Foo foo{};
|
||||
Bar bar = foo.getBar(); // calls `Bar getBar() &`
|
||||
Bar bar = foo.getBar(); // calls `Bar& getBar() &`
|
||||
|
||||
const Foo foo2{};
|
||||
Bar bar2 = foo2.getBar(); // calls `Bar Foo::getBar() const&`
|
||||
Bar bar2 = foo2.getBar(); // calls `Bar& Foo::getBar() const&`
|
||||
|
||||
Foo{}.getBar(); // calls `Bar Foo::getBar() &&`
|
||||
std::move(foo).getBar(); // calls `Bar Foo::getBar() &&`
|
||||
|
||||
std::move(foo2).getBar(); // calls `Bar Foo::getBar() const&&`
|
||||
Foo{}.getBar(); // calls `Bar&& Foo::getBar() &&`
|
||||
std::move(foo).getBar(); // calls `Bar&& Foo::getBar() &&`
|
||||
std::move(foo2).getBar(); // calls `const Bar&& Foo::getBar() const&`
|
||||
```
|
||||
|
||||
### Trailing return types
|
||||
|
||||
Reference in New Issue
Block a user