1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#include <vector>
#include <array>
#include <iostream>
std::vector<int> foo() { return { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } ; } // return vector by value
std::array<int,10> bar() { return { { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } } ; } // return std::array by value
int main()
{
for( int v : foo() ) std::cout << v << ' ' ; // 0 1 2 3 4 5 6 7 8 9
std::cout << '\n' ;
for( int v : bar() ) std::cout << v << ' ' ; // 0 1 2 3 4 5 6 7 8 9
std::cout << '\n' ;
}
|