idioms - RawIron/learn-cpp GitHub Wiki

composition

C++20 ranges

configure

  • command-line arguments

  • configuration file

  • encode and decode Jason

functions, lambdas

  • function with multiple return values
pair<string, int> do_something() {
  ...
  return make_pair(name, age);
}

int main() {
  string name{};
  int age{};
  tie(name, age) = do_something();
}

containers

https://www.geeksforgeeks.org/the-c-standard-template-library-stl/

list operations: reverse, sum, filter, map, reduce

  • filter

  • sum
#include <numeric>

sum_of_scores = std::accumulate(scores.begin(), scores.end(),
                               decltype(scores)::value_type(0));

https://stackoverflow.com/questions/3221812/how-to-sum-up-elements-of-a-c-vector

  • C++20 list slices
[4:6]
[4:]
[:9]
[1:-3]
  • C++20 yield -> co-routines, generators
⚠️ **GitHub.com Fallback** ⚠️