You are on page 1of 5

CppCon 2018: Walter E. Brown “C++ Function Templates: How Do They Really Work?

-explicit specialization do not participate in overload resolution (because it is a declaration that does not
introduce a new name, like static_assert) [23.54]

-overload resolution does not take into account explicit specializations of function templates [40.30]

-advice [41.16]

-future [43.57]

Rule of Three Implementation in C++

-supraincarcarea lui = se ia atunci cand ambele obiecte sunt deja in existenta

-constructorul de copiere se ia atunci cand la initializarea unui obiect pui = alt obiect;

Dog class

-initial value of reference to non-const must be an lvalue

-eroarea asta apare cand functia are ca parametru o referinta care nu e const si in main() vreau sa ii
trimit ca parametru un rvalue, de exemplu 8

-practic functia asteapta un lvalue

Learn STL: Introduction of Templates

-putem scrie template <typename T> in loc de template <class T>

-pentru o clasa trebuie sa dai explicit tipul de date cand folosim template, pentru o functie compilatorul
isi poate da seama din tipul argumentului

Introduction of STL #6: Functors

-also called function objects, because you define a class and a function within it and use that function when
you insantiate the class

-you can have many functions defined in it, beyond operator()

-template arguments must be compile time constants which is not true in the case of functors (you don't
have to worry about that)

-we need functors when we use it for example with Set, because a Set sorts it's values automatically
and if you want to sort them in a different (custom) way, it takes a second argument set<int,
less<int>> mySet and that argument must be a function type, not just a function -> functor

-similar story with lambdas, you can create a readable function within your code which does the same
thing
[](int x) { return (x>20) || (x<5); }

C++ 11: Rvalue Reference - Perfect Fowarding

-T&& usually means rvalue reference, however there are cases when the compiler, based on the argument,
will deduce for T&& either an lvalue reference or an rvalue reference, for ex.:

-you can have a function template which passes either an lvalue reference or an rvalue reference:
template <typename T>
void relay(T&& arg) {

-for relay(9); the deduced type T = int&& => T&& = int&& && = int&& (note the double &
=> rvalue reference), where T&& is the function argument as seen above

-for relay(x); the deduced type T = int& => T&& = int& && = int & (lvalue reference)

-type deductions and reference collapsing rules:

T& & => T&

T& && => T&

T&& & => T&

T&& && => T&&

-note that only when you have double && twice you get an rvalue reference

-T&& is a universal reference only when T is a template type (so not int, char, etc.) and T is a function
template type, not class template type

Learn C++ 11 in 20 Minutes - Part I

-auto infers from rvalue (right side operator)

C++ Rvalue References Explained

-lvalue refers to a memory location which we can take the address of with the & operator

-rvalue refers to everything which is not an lvalue

-move semantics <-> pentru un rvalue noi vrem sa facem schimb de resurse (swap)

-pentru X definit ca tip de date (cum e int, long, etc.), & inseamna:
X var;
var& - lvalue (reference)
var&& - rvalue
void foobar() { ... }

void foo(X& var); - se foloseste pentru apel de genul: foo(x);, x fiind lvalue

void foo(X&& var); - se foloseste pentru apel de genul: foo(foobar());, foobar() fiind
rvalue

std::move() - turns argument into an rvalue

-if you declare a thing as rvalue, it can be either lvalue or rvalue:

-if it has a name -> lvalue

-if it doesn't have a name -> rvalue

-move semantics -> overload pentru copy constructor si overload pentru assignment operator (=)

-daca Base e clasa:


Base(rhs) -> face apel de constructor de copiere non-moving

Base(std::move(rhs)) -> face apel de constructor cu move semantics

-compilatorul -> return value optimization -> basically, builds an object directly at the location of a
function's return value:

void foo() { ... return ... }; //construieste obiectul exact acolo unde returneaza functia
foo()

-perfect forwarding =

-rvalues allow us to achieve perfect forwarding without overloads


Github
C:\Users\Praid se pune ca default directory la un repository ce l-ai
copiat

Observatii

(1) un fisier trebuie modificat in branch nou ca sa poti sa tragi un pull request

(2) inainte sa dai merge cu master branch dai un push de toate modificarile tale

(3) if you get merge conflicts, you need to git pull and solve conflicts within the file and then you will
be able to push to Git

(4) daca adaugi un fisier nou, dai checkout la master si adaugi fisierul cu add inainte de a face branch

1. Faci proiect in Visual

...

2. Creezi un branch nou


git checkout master
git branch branch_name
git push --set-upstream origin branch_name

3. Modifici un fisier in branch nou, vezi observatia (1)


git checkout branch_name
git add fisier_modificat

git commit -m "mesaj" //aici pui ce vrei sa faci "creez metoda insert()"
git push

4. Creezi un pull request de pe website, comparand master cu branch_name

5. Modifici in fisier si dai push pe branch


git checkout branch_name

*modifici fisier*
git add fisier_modificat

git commit -m "mesaj" //aici scriu ce am facut pentru metoda insert()


git push

6. Dai merge cu master branch


git checkout master
git merge branch_name
git push
git branch -d branch_name

You might also like