I'm in a bit of a pickle, following up my previous question and using a code similar to the one I posted here.
- I use a variadic template function which accepts variadic objects
- It packs them into a tuple
- Iterates them using the
visitoridiom - Binds for each object a callback
Instead of the original minified example shown below:
template <typename... Args> void make_classes(Args... args) { auto t = std::tuple<Args...>(args...); unsigned int size = std::tuple_size<decltype(t)>::value; auto execute = [](auto & obj){ obj.operator()(); }; for (int i = 0; i < size; i++) { visit_at(t, i, execute); } } I am trying to understand how I can deduce the template type of the auto lambda, so that I can bind it:
template <typename... Args> void make_classes(Args... args) { auto t = std::tuple<Args...>(args...); unsigned int size = std::tuple_size<decltype(t)>::value; auto execute = [](auto & obj){ // obtain type of obj as T? auto callback = std::bind(&T::deserialise, obj, std::placeholders::_1); // do something else here using this callback. }; for (int i = 0; i < size; i++) { visit_at(t, i, execute); } } There's a catch: the parameter objects are non-copyable (although I could change that), but I would like to know if/how the above could work by deducing the template type packed in the tuple as obtained by the visitor.
If I can't deduce the type inside the lambda, can I somehow store it within the tuple (e.g.,: type & object) in order to later extract it?
decltype(auto)?decltype(objreturnserror: type 'decltype(obj)' cannot be used prior to '::' because it has no memberswith the correct type printed in the error.objthen you just usedecltype(obj).