mirror of
https://github.com/AnthonyCalandra/modern-cpp-features.git
synced 2025-12-17 10:04:35 +03:00
Added ref-qualified member functions.
This commit is contained in:
29
README.md
29
README.md
@@ -74,6 +74,7 @@ C++11 includes the following new language features:
|
||||
- [inline-namespaces](#inline-namespaces)
|
||||
- [non-static data member initializers](#non-static-data-member-initializers)
|
||||
- [right angle brackets](#right-angle-brackets)
|
||||
- [ref-qualified member functions](#ref-qualified-member-functions)
|
||||
|
||||
C++11 includes the following new library features:
|
||||
- [std::move](#stdmove)
|
||||
@@ -1167,7 +1168,7 @@ class Human {
|
||||
};
|
||||
```
|
||||
|
||||
### Right angle Brackets
|
||||
### Right angle brackets
|
||||
C++11 is now able to infer when a series of right angle brackets is used as an operator or as a closing statement of typedef, without having to add whitespace.
|
||||
|
||||
```c++
|
||||
@@ -1175,6 +1176,32 @@ typedef std::map<int, std::map <int, std::map <int, int> > > cpp98LongTypedef;
|
||||
typedef std::map<int, std::map <int, std::map <int, int>>> cpp11LongTypedef;
|
||||
```
|
||||
|
||||
### Ref-qualified member functions
|
||||
Member functions can now be qualified depending on whether `*this` is an lvalue or rvalue reference.
|
||||
|
||||
```c++
|
||||
struct Bar {
|
||||
// ...
|
||||
};
|
||||
|
||||
struct Foo {
|
||||
Bar getBar() & { return bar; }
|
||||
Bar getBar() const& { return bar; }
|
||||
Bar getBar() && { return std::move(bar); }
|
||||
private:
|
||||
Bar bar{};
|
||||
};
|
||||
|
||||
Foo foo{};
|
||||
Bar bar = foo.getBar(); // calls `Bar getBar() &`
|
||||
|
||||
const Foo foo2{};
|
||||
Bar bar2 = foo2.getBar(); // calls `Bar Foo::getBar() const&`
|
||||
|
||||
Foo{}.getBar(); // calls `Bar Foo::getBar() &&`
|
||||
std::move(foo).getBar(); // calls `Bar Foo::getBar() &&`
|
||||
```
|
||||
|
||||
## C++11 Library Features
|
||||
|
||||
### std::move
|
||||
|
||||
Reference in New Issue
Block a user