I have a function that is part of a class handles some input as pair of iterators. The signature of which is:
class Obj {
public:
template <typename InputIterator>
void handle_read(InputIterator first, InputIterator last);
...
};
I would like to bind that to a function:
void Obj::handle_connect() {
connections.start(std::make_shared<connection>(std::move(socket), connections, logger),
std::bind(&server::handle_read<InputIterator>, this, std::placeholders::_1, std::placeholders::_2));
}
However that doesn't work, specifically the error suggests that it can't find InputIterator.
However if I put the exact signature for the bind in:
std::bind(&server::handle_read<std::array<uint8_t, 8192>::iterator>, this, std::placeholders::_1, std::placeholders::_2));
It compiles, but the code is brittle: If I change to a vector then I will need to go around changing the signatures (though failing code will be easy to detect), and if I decide that a different container would be more efficient than an array in a particular use case, then it breaks altogether.
How I do keep the bind generic and not tied to a particular iterator type?
Aucun commentaire:
Enregistrer un commentaire