Using std::array
suggest changeThe container std::array can bundle together a fixed number of return values. This number has to be known at compile-time and all return values have to be of the same type:
std::array<int, 4> bar(int a, int b) {
return { a + b, a - b, a * b, a / b };
}
This replaces a C-style array of the form int bar[4]. A C array cannot be returned by value. Standard-library algorithms can be used on std::array. at checks the index, and size reports the number of elements. std::array is C++11. As in the output-parameter example, a / b is undefined when b is 0.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents