The C++11 introduced - std::array - is a thin wrapper on a standard C-style array. When a C-style array is passed to a function it decays to a pointer and loses the information about its size. The std::array overcomes this drawback, as it wraps a C-style array and provides properties - size, and empty - for querying the number of elements in the array. You can read more about std::array at C++ Reference.
Here is a question that compares std::array with C-style array. We declare a std::array, and a C-style array with similar content in main():
int main() {
std::array<int, 5> stdArray = { 1, 2, 3, 4, 5 };
int csArray[5] = { 1, 2, 3, 4, 5 };
//........ more code ......
return 0;
}
We also have two functions - Foo() and Bar(). Foo() accepts a collection by reference and uses a range-based for loop to iterate over all the elements of the collection to modify them. Whereas, Bar() accepts a collection by value, and uses the range-based for loop on the collection to print all its elements.
// collection by reference
template<typename C>
void Foo(C& collection) {
for(auto& t : collection)
t++;
}
// collection by value
template<typename C>
void Bar(C collection) {
for(auto& t : collection)
std::cout << t;
}
Select all those statements below that are true about above code: