Tyler Howard
DevTricks 08/11/15
Basically the rest of this talk's topic
unique_ptr<T>
shared_ptr<T>
weak_ptr<T>
void someFunction()
{
int* p = new int(5);
// ...
delete p;
}
void someFunction()
{
shared_ptr<int> p(new int(5));
// ...
//implicit ~p on function return
}
auto
decltype
int x = 5;
auto x = 5; //x is still int
int x = 5;
decltype(x) y = x; //y is an int
auto addSelf(auto x)
{
return x + x;
}
//Compiler generates versions for both:
addSelf(5);
addSelf(std::string("Repeat"));
std::vector<std:pair<int, int>>::iterator it = tuples.begin();
//identical to:
auto it = tuples.begin();
Syntax of "for" expanded:
for(int i = 0; i < indices.size(); ++i)
{
x = indices[i];
}
equivalent to:
for(int x : indices)
Works for: C-style arrays, initializer lists, types with iterators