#include <fstream.hfa>
#include <stdlib.hfa>
#include <array.hfa>







forall( T, [Nclients], [Ncosts] )
struct request {
    unsigned int requestor_id;
    array( T, Nclients ) impacted_client_ids; // nested VLA
    array( float, Ncosts ) cost_contribs; // nested VLA
    float total_cost;
};


// TODO: understand (fix?) why these are needed (autogen seems to be failing ... is typeof as struct member nayok?)

forall( T, [Nclients], [Ncosts] )
	void ?{}( T &, request( T, Nclients, Ncosts ) & this ) {}

forall( T &, [Nclients], [Ncosts] )
	void ^?{}( request( T, Nclients, Ncosts ) & this ) {}














forall( T, [Nclients], [Ncosts] )
void summarize( request( T, Nclients, Ncosts ) & r ) {
    r.total_cost = 0;
    for( i; Ncosts )
        r.total_cost += r.cost_contribs[i];
    // say the cost is per-client, to make output vary
    r.total_cost *= Nclients;
}












int main( int argc, char * argv[] ) {
	const int ncl = ato( argv[1] );
	const int nco = 2;

	request( int, ncl, nco ) r;
	r.cost_contribs[0] = 100;
	r.cost_contribs[1] = 0.1;

	summarize(r);
	sout | "Total cost:" | r.total_cost;
}
/*
$\$$ ./a.out 5
Total cost: 500.5
$\$$ ./a.out 6
Total cost: 600.6
*/
