Auto
Move Semantics
*************************************
Auto
const reference vs mutable
|
Return type |
Syntactic variants (a, b,
and c correspond to the same result): |
|
Value |
auto val() const // a) auto,
deduced type auto val() const -> int // b) auto, trailing type int val() const // c)
explicit type |
|
Const reference |
auto& cref() const // a) auto,
deduced type auto cref() const -> const int& // b) auto,
trailing type const int& cref() const // c) explicit type |
|
Mutable reference |
auto& mref() // a) auto,
deduced type auto mref() -> int& // b) auto,
trailing type int& mref() // c)
explicit type |
decltype(auto) - nie musimy decydowa czy dac auto czy auto& - sam rozpozna
auto val_wrapper() { return val();
} // Returns int
auto mref_wrapper() { return mref(); } // Also
returns int
decltype(auto) val_wrapper() { return val();
} // Returns int
decltype(auto) mref_wrapper() { return mref(); } // Returns
int&
I recommend using const auto for fundamental types (int, float, and so on) and small non-fundamental types like std::pair and std::complex. For bigger types that are potentially expensive to copy, use const auto&.
auto& and auto should only be used when you require the behavior of a mutable reference or an explicit copy;
Move Semantics
konstruktory:
03 class Clazz {
04 public:
05 Clazz() noexcept; // Konstruktor domyślny.
06 Clazz(const Clazz& other); // Konstruktor kopiujący.
07 Clazz(Clazz&& other) noexcept; // Konstruktor przenoszący.
08 Clazz& operator=(const Clazz& other); // Kopiujący operator przypisania.
09 Clazz& operator=(Clazz&& other) noexcept; // Przenoszący operator przypisania.
10 virtual ~Clazz() noexcept; // Destruktor.
&& rvalue - it is just an object that is not tied to a named variable
• It's coming straight out of a function
• We make a variable an rvalue by using std::move()
...