C++ (11) Docs
C++ (11) Docs
2.
4.
5.
6. Auto stripes out all the cv-qualifiers from a declaration. (like const, &, * anything).
Const auto& x = I;
7. But decltype automatically deduces the complete type without evaluating the value.
s
8. Auto and decltype conversion happened in compile time. Now what compiler interpret the
type for auto or decltype, no ways to know.
form the error message, we can see the compiler interpreted type.
We can also use typeid to know the compiler interpreted type. But it is in a compiler
dependent format which is different compiler to compiler, which is really hard to decode
the type from the format.
Summary:
1. auto
2. decltype
3. decltype(auto)
4. compiler deduced type (error msg / typeid)
5. suffix / trailing return type (old – new)
6. The example
C++(11) features – part 2
1. Initializer list
3. std::initializer list stores initializer values in an array and offers these member functions:
◦ size // # of elements in the array
◦ begin // ptr to first array element
◦ end
4.
5. vector<double> v1{7};
7.
8.
11. Non-aggregate (We have to give exactly same parameter in this case)
12.
13.
Summary:
1. For function calling, () this must be used, f {1, 2} this is totally not supported. This brace
is only for initialization purpose, not invoking functions.
2. Initializer list
6. Aggregate vs non-aggregate
1. Constexpr : when we need to calculate an expression at the compile time, then we should
use constexpr as a suffix.
If operator | is not initialized at the compile time, the switch statement gives an error.
2.
Because we will get the value of f3 at run time, so constexpr is not applicable here.
3. M – 48.10 - const
4. Static constexpr
5.
6.
array is of fixed size, so it can be done.
https://chatgpt.com/c/6711d8eb-8a0c-8009-a258-277b920273b5
8.
0 -> int
NULL -> may be integer, may be a pointer to 0. (Here its pointer, so ambiguity)
10.
0 -> int
13. Static_assert
s
14. user-defined literals
read the codes. (double is not allowed, use long double as signature)
Here u don’t need to use escape characters. Here we can easily print multi lines.
s
17. Some more: https://chatgpt.com/c/6711eafc-7c0c-8009-9286-8f8078797305
Summary:
1. Constexpr
Const, static, vector, array
2. Noexcept
3. 0 vs NULL vs nullptr (Reg func. vs template forwarding)
4. Inline namespace
5. Static_assert
6. User defined literals(long double)**
7. Digit separators and binary literals
8. Raw string
9. more
10.
C++(11) features – part 4
1. Copying vs moving
swapping by move
2. lvalue and rvalue.
Lvalue
Rvalue
Examples.
Rvalue references (T&&) are primarily intended to enable move semantics. A const
rvalue reference (const T&&) means that the rvalue reference points to a constant
object, which cannot be modified.
This means you cannot move from it because moving inherently involves altering the
state of the original object (leaving it in an unspecified state).
So, const rvalue reference commonly not used!!
s
In move semantics, dtor = nullptr as we are moving, that means we are using the existing
resource.
So, that will be destroyed only after full execution of the code.
Summary:
1.
mRrc = c.mRrc; still copying thing. As c has a address, it is a lvalue, which matches with
the copy constructor version not with the move one.
4.
reference collapsing in cpp says that if any one of the references is a lvalue reference, the
resultant will be a lvalue reference.
If both are rvalue reference, then only the resultant will be a rvalue reference.
6. Std::move return type. (Should always return a rvalue..now how to ensure that?)
7. Parameter type.
9. The return type of a lvalue ref should be lvalue and rvalue -> rvalue.
Summary:
1. Summary:
If it is a function respect to the context of templates, rvalue reference tales takes lvalue
or rvalue, const or non-const. As it follows the rules of reference collapsing.
s
3. Perfect forwarding problem
4. solution: std::forward
5. Type safety
That means perfect forwarding is totally type-safe.
C++(11) features – part 7
3. Instant calling.
4. call by Reference.
5. = operator in capture clause.
It will copy all the variables defined in the scope only which are required in the lambda.
(before the lambda).
8.
9.
TIPS: when we are modifying something and that is associated with lambda then we must
use &.Otherwise we can use =.
12.
In case of mutable, we can change value locally using capture by value. The change made
in the expression body doesn’t reflect on the original one.
1. Std::function
2. Slide – 9
3. Pipelining
Slide 13: for generic lambda, we need to explicitly convert const char* to string.
s
5. Capture-less Generic λ can be conv. to Function Pointers.
6. Recursive λ expression.
Problem:
Summary:
First example (why m_ will not work, this or = work)
Std::function
Pipeline
Generic lambda
Capture less generalized lambda -> function pointers
Recursive lambda problem & sol.
Generalized lambda captures
C++(11) features – part 9
Rule of five
Rule of three
Rule of zero
https://chatgpt.com/c/6714fbcb-0cf4-8009-b182-275d4a5d3175
3. Delegating constructors
https://chatgpt.com/c/6720f0ba-1f08-8009-bb3a-c519d37961c5
https://chatgpt.com/c/6720f0ba-1f08-8009-bb3a-c519d37961c5
https://chatgpt.com/c/6720f0ba-1f08-8009-bb3a-c519d37961c5
VVI- PPT example
https://chatgpt.com/c/671500b1-20a4-8009-a783-a3c5f599ee34
https://chatgpt.com/c/6721025e-7a5c-8009-a21e-b12390e039be (BOOL)
C++(11) features – part 10
1. enum in c++(11).
2.
8.
9. If you give a value greater in size than the underlying type, it will show a error.
10.
11. In c++(03), for forward declaration you must give a size.
12. In c++(11), the underlying type is int by default.
15.