Skip to content

Commit 9852478

Browse files
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>
1 parent 090b412 commit 9852478

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

CPP11.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -619,23 +619,23 @@ struct Bar {
619619
};
620620

621621
struct Foo {
622-
Bar getBar() & { return bar; }
623-
Bar getBar() const& { return bar; }
624-
Bar getBar() && { return std::move(bar); }
622+
Bar& getBar() & { return bar; }
623+
const Bar& getBar() const& { return bar; }
624+
Bar&& getBar() && { return std::move(bar); }
625+
const Bar&& getBar() const&& { return std::move(bar); }
625626
private:
626627
Bar bar;
627628
};
628629

629630
Foo foo{};
630-
Bar bar = foo.getBar(); // calls `Bar getBar() &`
631+
Bar bar = foo.getBar(); // calls `Bar& getBar() &`
631632

632633
const Foo foo2{};
633-
Bar bar2 = foo2.getBar(); // calls `Bar Foo::getBar() const&`
634+
Bar bar2 = foo2.getBar(); // calls `Bar& Foo::getBar() const&`
634635

635-
Foo{}.getBar(); // calls `Bar Foo::getBar() &&`
636-
std::move(foo).getBar(); // calls `Bar Foo::getBar() &&`
637-
638-
std::move(foo2).getBar(); // calls `Bar Foo::getBar() const&&`
636+
Foo{}.getBar(); // calls `Bar&& Foo::getBar() &&`
637+
std::move(foo).getBar(); // calls `Bar&& Foo::getBar() &&`
638+
std::move(foo2).getBar(); // calls `const Bar&& Foo::getBar() const&`
639639
```
640640
641641
### Trailing return types

CPP17.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ std::vector v{ 1, 2, 3 }; // deduces std::vector<int>
369369
std::mutex mtx;
370370
auto lck = std::lock_guard{ mtx }; // deduces to std::lock_guard<std::mutex>
371371

372-
auto p = new std::pair{ 1.0, 2.0 }; // deduces to std::pair<double, double>
372+
auto p = new std::pair{ 1.0, 2.0 }; // deduces to std::pair<double, double>*
373373
```
374374
375375
For user-defined types, *deduction guides* can be used to guide the compiler how to deduce template arguments if applicable:

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ std::vector v{ 1, 2, 3 }; // deduces std::vector<int>
10331033
std::mutex mtx;
10341034
auto lck = std::lock_guard{ mtx }; // deduces to std::lock_guard<std::mutex>
10351035

1036-
auto p = new std::pair{ 1.0, 2.0 }; // deduces to std::pair<double, double>
1036+
auto p = new std::pair{ 1.0, 2.0 }; // deduces to std::pair<double, double>*
10371037
```
10381038
10391039
For user-defined types, *deduction guides* can be used to guide the compiler how to deduce template arguments if applicable:
@@ -2096,23 +2096,23 @@ struct Bar {
20962096
};
20972097

20982098
struct Foo {
2099-
Bar getBar() & { return bar; }
2100-
Bar getBar() const& { return bar; }
2101-
Bar getBar() && { return std::move(bar); }
2099+
Bar& getBar() & { return bar; }
2100+
const Bar& getBar() const& { return bar; }
2101+
Bar&& getBar() && { return std::move(bar); }
2102+
const Bar&& getBar() const&& { return std::move(bar); }
21022103
private:
21032104
Bar bar;
21042105
};
21052106

21062107
Foo foo{};
2107-
Bar bar = foo.getBar(); // calls `Bar getBar() &`
2108+
Bar bar = foo.getBar(); // calls `Bar& getBar() &`
21082109

21092110
const Foo foo2{};
2110-
Bar bar2 = foo2.getBar(); // calls `Bar Foo::getBar() const&`
2111+
Bar bar2 = foo2.getBar(); // calls `Bar& Foo::getBar() const&`
21112112

2112-
Foo{}.getBar(); // calls `Bar Foo::getBar() &&`
2113-
std::move(foo).getBar(); // calls `Bar Foo::getBar() &&`
2114-
2115-
std::move(foo2).getBar(); // calls `Bar Foo::getBar() const&&`
2113+
Foo{}.getBar(); // calls `Bar&& Foo::getBar() &&`
2114+
std::move(foo).getBar(); // calls `Bar&& Foo::getBar() &&`
2115+
std::move(foo2).getBar(); // calls `const Bar&& Foo::getBar() const&`
21162116
```
21172117
21182118
### Trailing return types

0 commit comments

Comments
 (0)