flat_map


1. Flatten a Vector of Vectors

#include <vector>
#include <iostream>
#include <algorithm>

int main() {
  std::vector<std::vector<int>> v = {{1, 2}, {3, 4}, {5, 6}};

  std::vector<int> flattened = std::vector<int>(v.size() * v[0].size());
  std::transform(v.begin(), v.end(), flattened.begin(),
                 [](const std::vector<int>& inner) { return inner.begin(); });

  for (int num : flattened) {
    std::cout << num << " ";
  }

  return 0;
}

2. Flatten a Map of Vectors

3. Flatten a Set of Vectors

4. Flatten a List of Tuples

5. Flatten a Vector of Optionals

6. Flatten a Map of Optionals

7. Flatten a Set of Optionals

8. Flatten a List of Iterables

9. Flatten a Vector of Pairs

10. Flatten a Map of Pairs