1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
#ifndef UPDATE_HPP
#define UPDATE_HPP

#include <cstdlib>
#include <utility>

namespace update_with_index_impl {

   template<typename F, typename Variable>
   void update(F&& f, std::size_t size, std::size_t index, Variable& var) {
      f(size, index, var);
   }

   template<typename F, typename Variable, typename... Variables>
   void update(F&& f, std::size_t size, std::size_t index,
	 Variable& var, Variables&... vars) {
      f(size, index, var); update(std::move(f), size, index+1, vars...);
   }

} // namespace update_with_index_impl

template<typename F, typename... Variables>
void update_with_index(F&& f, Variables&... vars) {
   update_with_index_impl::update(std::move(f),
      sizeof...(vars), 0, vars...);
}

#endif