現在、set< T > および set< set< T > > を生成するセット式評価器を作成しています。以下のコードは、式の結果を表示するためのものです。
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);
そのような2つの行があり、それらはトレースを生成します..
e:\documents\level 3\advanced software engineering\coursework\coursework\boost\variant\detail\apply_visitor_unary.hpp(76): エラー C2039: 'apply_visitor': 'std::set<_Kty>' のメンバーではありません1> with 1> [ 1> _Kty=std::string 1> ] 1> e:\documents\level 3\advanced software engineering\coursework\coursework\context.h(96) : 関数テンプレートのインスタンス化 'std への参照を参照してください::basic_string<_Elem,_Traits,_Ax> boost::apply_visitor::ExpressionTree::string_visitor,const std::set<_Kty>>(const Visitor &,Visitable &)' が 1> [ 1> _Elem でコンパイルされている=char, 1> _Traits=std::char_traits, 1> _Ax=std::allocator, 1> T=std::string, 1> _Kty=std::string, 1> Visitor=Context::ExpressionTree::string_visitor, 1> Visitable=const 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>) const' 1> with 1> [ 1> T=std::string をコンパイル中、 1> _Kty=std::set 1> ] 1> e:\documents\level 3\advanced software engineering\coursework\coursework\context.cpp(337) : クラス テンプレートのインスタンス化への参照を参照してください 'Context::ExpressionTree::string_visitor ' コンパイル中 1> with 1> [ 1> T=std::string 1> ]ExpressionTree::string_visitor, 1> Visitable=const 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>) const' 1> with 1> [ 1> T=std::string, 1> _Kty=std::set 1 > [ 1> T=std::文字列 1> ]ExpressionTree::string_visitor, 1> Visitable=const 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>) const' 1> with 1> [ 1> T=std::string, 1> _Kty=std::set 1 > [ 1> T=std::文字列 1> ]] 1> e:\documents\level 3\advanced software engineering\coursework\coursework\context.h(90) : クラス テンプレート メンバー関数のコンパイル中 'std::string Context::ExpressionTree::string_visitor::operator ()( std::set<_Kty>) const' 1> with 1> [ 1> T=std::string, 1> _Kty=std::set 1> ] 1> e:\documents\level 3\高度なソフトウェア工学\ coursework\coursework\context.cpp(337) : 1> [ 1> T=std::string 1> ] でコンパイルされているクラス テンプレートのインスタンス化 'Context::ExpressionTree::string_visitor' への参照を参照してください] 1> e:\documents\level 3\advanced software engineering\coursework\coursework\context.h(90) : クラス テンプレート メンバー関数のコンパイル中 'std::string Context::ExpressionTree::string_visitor::operator ()( std::set<_Kty>) const' 1> with 1> [ 1> T=std::string, 1> _Kty=std::set 1> ] 1> e:\documents\level 3\高度なソフトウェア工学\ coursework\coursework\context.cpp(337) : 1> [ 1> T=std::string 1> ] でコンパイルされているクラス テンプレートのインスタンス化 'Context::ExpressionTree::string_visitor' への参照を参照してください文字列 Context::ExpressionTree::string_visitor::operator ()(std::set<_Kty>) const' 1> with 1> [ 1> T=std::string, 1> _Kty=std::set 1> ] 1> e:\documents\level 3\advanced software engineering\coursework\coursework\context.cpp(337) : クラス テンプレートのインスタンス化への参照を参照してください 'Context::ExpressionTree::string_visitor' がコンパイルされています 1> [ 1> T=標準::文字列 1> ]文字列 Context::ExpressionTree::string_visitor::operator ()(std::set<_Kty>) const' 1> with 1> [ 1> T=std::string, 1> _Kty=std::set 1> ] 1> e:\documents\level 3\advanced software engineering\coursework\coursework\context.cpp(337) : クラス テンプレートのインスタンス化への参照を参照してください 'Context::ExpressionTree::string_visitor' がコンパイルされています 1> [ 1> T=標準::文字列 1> ]1> [ 1> T=std::string 1> ] でコンパイルされているクラス テンプレートのインスタンス化 'Context::ExpressionTree::string_visitor' への参照を参照してください。1> [ 1> T=std::string 1> ] でコンパイルされているクラス テンプレートのインスタンス化 'Context::ExpressionTree::string_visitor' への参照を参照してください。
その種の呼び出しを表現する方法を知っている人はいますか?
乾杯、アレックス