At the moment I am using optional arguments as shown below, which forms a vector with all arguments up to the last non-empty argument.
Is there a nicer\recommended way of doing this?
- Code: Select all
CellMatrix SortArrayV(CellMatrix rng,
CellMatrix sort_key_01, CellMatrix sort_dir_01,
CellMatrix sort_key_02, CellMatrix sort_dir_02,
CellMatrix sort_key_03, CellMatrix sort_dir_03,
...
CellMatrix sort_key_20, CellMatrix sort_dir_20
)
{
std::vector<CellMatrix> args;
args.push_back(sort_key_01); args.push_back(sort_dir_01);
args.push_back(sort_key_02); args.push_back(sort_dir_02);
args.push_back(sort_key_03); args.push_back(sort_dir_03);
...
args.push_back(sort_key_20); args.push_back(sort_dir_20);
while (args.size()>0)
{
if (args.back().ColumnsInStructure() == 1 &&
args.back().RowsInStructure() == 1 &&
args.back()(0, 0).IsEmpty())
{
args.pop_back();
}
else
break;
}
return CellMatrix((double)args.size());
}
Note I also tried another method which took a pointer to the first variable argument, max number of arguments and went from there.
It caused Excel to crash so I abandoned that method, I also wasn't sure how the compiler would allocate the args so it seems very suspect either way.
- Code: Select all
std::vector<CellMatrix> GetParamsArray(IN CellMatrix* ary, IN uint16_t max_num_params, OUT std::vector<CellMatrix>& args) {
std::vector<CellMatrix> args_skipped;
args_skipped.reserve(max_num_params);
for (uint16_t i = 0; i < max_num_params; i++) {
bool skip = ary[i].ColumnsInStructure() == 1 && ary[i].RowsInStructure() == 1 && ary[i](0, 0).IsEmpty();
if (skip)
{
args_skipped.push_back(ary[i]);
}
else
{
if (args_skipped.size()>0){
args.insert(args.end(), args_skipped.begin(), args_skipped.end());
args_skipped.clear();
}
args.push_back(ary[i]);
}
}
}