
On 10/15/2016 5:15 PM, Larry Evans wrote:
On 10/15/2016 04:06 PM, Larry Evans wrote:
template<std::size_t N, typename... Fields> using soa_citizens_t= std::tuple < std::array<N,Fields>... > ;
? Then wouldn't:
std::size_t n=5; soa_citizens_t<n,string,string,int,int> soa_citizens; int avg = 0; int t = 1; std::size_t const salary=2 for( int salary: get<salary>(soa_citizens)) { avg += (salary - avg) / t; ++t; }
FWIW, the attached compiles and runs with:
Indeed this works well for a fixed sized dataset. It doesn't have the wasted duplicated information that a tuple of std::vectors has. It still doesn't provide an interface to query the soa directly for an iterator or size etc. Both a fixed-sized and dynamic-growth container are useful. Although I tend to need dynamic growth more often.