vendredi 8 septembre 2017

Alternative for std::bind in modern C++

So I'm trying to create a class which has a container for functors of a different type.

This is a simplified version of it.

template<class T>
class Container
{

public:
    template<typename F, typename ... ARGS>
    void addTask(F && func, ARGS && ... args);
private:
    std::deque<std::function<T()>> container;

    //.....
};

template<class T>
template<typename F, typename ... ARGS>
T Container<T>::addTask(F && func, ARGS && ... args);
{
    container.emplace_back(std::bind(f,args...));

    //.....
}

There are still few problems that I cannot solve yet.

  1. Is there a way to remove std::bind and store a different object or a pointer?
  2. Could this be more generic? Can I somehow store functions, which return different objects, in a single container?
  3. Can some of the logic for creating the tasks be executed in compile time?Something like consexpr bind.

Aucun commentaire:

Enregistrer un commentaire