【发布时间】:2010-12-14 00:21:26
【问题描述】:
我目前正在写一个set表达式求值器,生成set
class string_visitor : public boost::static_visitor<string>
{
public:
string operator()(bool value) const
{
return "{}";
}
string operator()(set<T> value) const
{
set<T>::const_iterator it = value.begin();
string output = "{";
if(!value.empty())
{
output += *it; // Return an empty set if necessary.
++it;
}
for(; it != value.end(); ++it)
{
output += " " + *it;
}
output += "}";
return output;
}
string operator()(set<set<T> > value) const
{
set<set<T> >::const_iterator it = value.begin();
string output = "{";
if(!value.empty())
{
output += boost::apply_visitor(string_visitor(), *it); // Return an empty set if necessary.
++it;
}
for(; it != value.end(); ++it)
{
output += " " + boost::apply_visitor(string_visitor(), *it);
}
output += "}";
return output;
}
};
当我尝试使用集合代码评估集合集时,我遇到的问题正在发生,显然我正在使用它,因为它是一种很好的做法,但编译器似乎不喜欢我用来构造打电话。
output += boost::apply_visitor(string_visitor(), *it);
有两条这样的线,它们会产生痕迹..
e:\documents\level 3\advanced software engineering\coursework\coursework\boost\variant\detail\apply_visitor_unary.hpp(76) : error C2039: 'apply_visitor' : is not a member of 'std::set' 1> 与 1> [ 1> _Kty=std::字符串 1>] 1> e:\documents\level 3\advanced software engineering\coursework\coursework\context.h(96) : 见参考函数模板实例化 'std::basic_string<_elem> boost::apply_visitor::ExpressionTree ::string_visitor,const std::set<_kty>>(const Visitor &,Visitable &)' 正在编译 1> 与 1> [ 1> _Elem=字符, 1> _Traits=std::char_traits, 1> _Ax=std::分配器, 1> T=std::字符串, 1> _Kty=std::字符串, 1> 访客=上下文::ExpressionTree::string_visitor, 1> 可访问=常量 std::set 1>] 1> e:\documents\level 3\advanced software engineering\coursework\coursework\context.h(90) : 在编译类模板成员函数'std::string Context::ExpressionTree::string_visitor::operator ()(std ::set<_kty>) 常量' 1> 与 1> [ 1> T=std::字符串, 1> _Kty=std::set 1>] 1> e:\documents\level 3\advanced software engineering\coursework\coursework\context.cpp(337) : 请参阅正在编译的类模板实例化 'Context::ExpressionTree::string_visitor' 的参考 1> 与 1> [ 1> T=std::字符串 1>]
有人知道如何表达这种呼叫吗?
干杯, 亚历克斯
【问题讨论】:
标签: boost set variant evaluator