What would be the preferred way to create a long Sum with a variable number of int
s?
My guess is something like this:
expr mk_add(expr_vector args) {
vector<Z3_ast> arr;
for (int i = 0; i < (int)args.size(); i++)
arr.push_back(args[i]);
return to_expr(args.ctx(), Z3_mk_add(args.ctx(), arr.size(), &arr[0]));
}
Is this Correct?
Yes, that looks correct. Just remember to be careful with Z3_ast
objects as their reference counts are not updated automatically (here to_expr
should take care of that).
Another solution that stays within the C++ API and doesn't need awkward translations is this:
expr mk_add(expr_vector args) {
expr r = args[0];
for (int i = 1; i < (int)args.size(); i++)
r = to_expr(args.ctx(), r + args[i]);
return r;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.