理想的には、次の型を宣言したいと思います。
using action_t = std::function< std::vector< action_t >(void) >
これはフォローアップ サンクのベクトルを返すサンクです。Recursive typedef function definition : std::function return its own typeからの情報を使用して、ここまで取得できました。
struct RecursiveHelper
{
typedef std::vector<RecursiveHelper> rtype;
typedef std::function< rtype (void) > ftype;
RecursiveHelper( ftype f ) : func(f) {}
rtype operator()() const { return func(); }
operator ftype () { return func; }
ftype func;
};
using action_t = RecursiveHelper;
using actions_t = std::vector<RecursiveHelper>;
ただし、たとえば、これらをスタックにプッシュするには、次のようにする必要があります。
std::stack<action_t> stack;
stack.push(RecursiveHelper([&visitor, &node](void){
return visitor.visitNode(node);
}));
理想的には、このようなものを使用するコードでの言及を避けたいと思いRecursiveHelper
ます。action_t のスタックが必要な場合は、適合するラムダを直接プッシュできるはずです。
これを達成する方法はありますか?