简体   繁体   English

使用Z3的C ++ api创建一个长和?

[英]Create a long Sum using the C++ api of Z3?

What would be the preferred way to create a long Sum with a variable number of int s? 使用可变数量的int创建长Sum的首选方法是什么?

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). 请记住要小心使用Z3_ast对象,因为它们的引用计数不会自动更新(这里to_expr应该处理它)。

Another solution that stays within the C++ API and doesn't need awkward translations is this: 保留在C ++ API中并且不需要笨拙翻译的另一种解决方案是:

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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM