diff --git a/CPP11.md b/CPP11.md index ae6e9ea..82ce077 100644 --- a/CPP11.md +++ b/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 diff --git a/CPP17.md b/CPP17.md index 0e0da39..ea02cf9 100644 --- a/CPP17.md +++ b/CPP17.md @@ -369,7 +369,7 @@ std::vector v{ 1, 2, 3 }; // deduces std::vector std::mutex mtx; auto lck = std::lock_guard{ mtx }; // deduces to std::lock_guard -auto p = new std::pair{ 1.0, 2.0 }; // deduces to std::pair +auto p = new std::pair{ 1.0, 2.0 }; // deduces to std::pair* ``` For user-defined types, *deduction guides* can be used to guide the compiler how to deduce template arguments if applicable: diff --git a/README.md b/README.md index b830084..b7ced0a 100644 --- a/README.md +++ b/README.md @@ -1033,7 +1033,7 @@ std::vector v{ 1, 2, 3 }; // deduces std::vector std::mutex mtx; auto lck = std::lock_guard{ mtx }; // deduces to std::lock_guard -auto p = new std::pair{ 1.0, 2.0 }; // deduces to std::pair +auto p = new std::pair{ 1.0, 2.0 }; // deduces to std::pair* ``` 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 { }; 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