我在使用Z3 :: expr作为地图值类型时遇到了困难。编译器抱怨不能使用默认构造函数。玩具示例如下所示。
#include <z3++.h>
#include <map>
//#include <vector>
using namespace std;
using namespace z3;
int main() {
map <int, expr> m;
context c;
m[1] = c.bool_const("x");
return 0;
}
编译器(Clang ++)抱怨
no matching constructor for initialization of 'mapped_type' (aka 'z3::expr')
__i = insert(__i, value_type(__k, mapped_type()));
in instantiation of member function 'std::map<int, z3::expr, std::less<int>,
std::allocator<std::pair<const int, z3::expr> > >::operator[]' requested here
m[1] = c.bool_const("x");
/usr/include/z3++.h:562:9: note: candidate constructor not viable: requires single argument 'c', but no arguments were provided
expr(context & c):ast(c) {}
^
/usr/include/z3++.h:564:9: note: candidate constructor not viable: requires single argument 'n', but no arguments were provided
expr(expr const & n):ast(n) {}
^
/usr/include/z3++.h:563:9: note: candidate constructor not viable: requires 2 arguments, but 0 were provided
expr(context & c, Z3_ast n):ast(c, reinterpret_cast<Z3_ast>(n)) {}
使用向量将map中的expr或find方法包装为替代似乎没问题。有没有办法直接使用expr作为地图值类型+ []运算符?