jgoenetxea
4/5/2018 - 7:26 AM

Usefull C++ standard notes

// ** Some implementations of c++ standard features **

// + Vector initialization
std::vector<int> numbers = {1, 2, 3, 4, 5};

void f(int number) {
  // make cool staff
}

// + For_each ('f' is a function)
std::for_each(begin(numbers), end(numbers), f);

// + For_each with lamda functions (less user friendly)
std::for_each(begin(numbers), end(numbers), [](int number){
  // make cool staff
});

// + NOTE:Usage of auto
//        auto -> Makes a copy of each element
//        auto& -> makes a non-const reference of each element
//        auto const & -> Makes a constant reference of each element

// + Range-based loops
for (auto number : numbers) {
  // make cool staff
}