Look at what you need the pack to unfold to: ((root.get()->*left).get()->*right).get()->*right).get();
And compare it with the definition of binary left fold ((((init op E0) op E1) op E2) ...)
This one is better written recursively.
1 2 3 4 5 6 7 8 9 10 11
template <typename T>
T* traverse(T* last)
{
return last;
}
template <typename T, typename U, typename... Vs>
auto traverse(T* root, U ptr_mem, Vs... ptr_mems)
{
return traverse((root->*ptr_mem).get(), ptr_mems...);
}