私は現在、セット< T>を生成し、<を< 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:\ドキュメント\レベル3 \高度なソフトウェアエンジニアリング\授業\授業\ブースト\バリアント\詳細\のapply_visitor_unary。 HPP(76):エラーC2039: 'apply_visitor' は: 1のメンバーではない 'スタンダード::設定< _Kty>' 1>> [ 1> _Kty = STD ::ストリング 1>] 1> e:¥documents¥level 3¥advanced software engineering¥coursework¥coursework¥context.h(96):以下の関数テンプレートへの参照を参照してください。 stantiation 'のstd :: < _Elem、_Traits、_Ax>ブースト:: apply_visitorをのbasic_string :: ExpressionTree :: string_visitor、constのはstd :: < _Kty設定>>(constのビジター&、訪問可能&)' は 1で> 1をコンパイルされています> [ 1> _Elem = CHAR、 1> _Traits = STD :: char_traits、 1> _Ax = STD ::アロケータ、 1> T = STD ::文字列、 1> _Kty = STD ::文字列、 1> Visitor = Context :: ExpressionTree :: string_visitor、 1> Visitable = const std :: set 1> 1> e:\ documents \ advancedソフトウェアエンジニアリング\ coursework \ coursework \ context.h(90 ):クラステンプレートメンバ関数 ' std :: string Context :: ExpressionTree :: string_visitor :: operator()(std :: set <_Kty>)const ' 1> で1> [ 1> T = std :: string、 1> _Kty = std :: set 1>] > e:\ documents \ advanced software engineering \ coursework \ coursework \ context.cpp(337):クラステンプレートのインスタンス化への参照を参照してください 'Context :: ExpressionTree :: string_visitor' > 1で 1>をコンパイルし、[ 1> T =のstd ::文字列 1>]
誰がどのようにフレーズコールの並べ替えをするの任意のアイデアを持っていますか?
乾杯、 アレックス
単純型キャストバック、私は定義されたバリアントの型に変数をすることによって、問題を解決するために管理
Lathford:(setconst&value'のように)(a)危険な安全でないキャストを避ける、(b) 'set'の場合に不要なコピーを避ける、あなたのパラメータを' const ' (c)誤って表現ツリーを変更することを防ぐことができます。これは、おそらく、きれいな印刷には合理的です。 – phooji