AMDG Dominique Devienne wrote:
// Context: retrieving all the rows (result set) from a given SQL query. // pseudo code of boilerplate code I keep repeating right now struct { int id; std::string name; } Row; void doit() { ResultSet rset = sql_exec("select id, name from t"); std::vector<Row> rows; while (rset.hasMoreRows()) { Row row; row.id = rset.get<int>(0); row.name = rset.get
(1); rows.push_back(row); } // process rows } // Code I'd like to write instead void doit() { typedef boost::tuple
Row; std::vector<Row> rows; sql_get_rows("select id, name from t", rows); // optional arg to get only first N elements // process rows } PS: returning the vector would be better, but because of the copy involved I guess I must pass it as a non-const ref instead, to fill it up. Will the new move semantic from the upcoming standard allow a function to return the vector without the copy? Just curious
In this case, I think Boost.Fusion can help (warning untested).
#include