lundi 29 février 2016

Recursive(?) function wrapper based on std::function<>

I want to achieve code looking similar to that

using ProcessCallback = std::function<ProcessCallback (const std::vector<char>&)>

// ...

ProcessCallback callback;
// initialize callback somehow...

while (/* condition */)    {
    auto callback_successor = callback (data);
    if (callback_successor)   {
       callback = std::move (callback_successor);
    }
}

In general I want to have callable callback object (function pointer, whatever) that will process some data and has possibly of replacing itself for successive calls.

The error is obvious - quasi-recursive declaration in first line is invalid, because I try to declare std::function<>-based type using undeclared ProcessCallback.

How can I fix aforementioned code or how can I achieve desired functionality with other construction? Abstract functional class for processing it's not the solution - I don't want to write new class inheriting from the abstract class for each processing function.

I want to stick to pure C++ (no Boos etc.), but I'm not limited to specific C++ version.

Aucun commentaire:

Enregistrer un commentaire