mercredi 27 avril 2016

Variadic templates. Some issues

template <class... T_values>
class Thing {
public:
  void something(T_values... values) {
    tuple_ = std::tuple<T_values...>(values...);
  }

  void do_something_with_values() {
     call_yadda_with_tuple(tuple_,
      std::index_sequence_for<T_value...>())
  }

  void yadda(T... values);

private:
  //The helper method.
  template<std::size_t... Is>
  void call_yadda_with_tuple(const std::tuple<T_values...>& tuple,
    std::index_sequence<Is...>) {
    yadda(std::get<Is>(tuple)...);
  }

  std::tuple<T_values...> tuple_;
};

Above sourcecode comes from: http://ift.tt/1LNyrjf

I would like to ask some questions:

  1. What does return std::index_sequence_for<T_value...>()) ?
  2. Why in yadda(std::get<Is>(tuple)...); there is Is instead of Is...? Therefore, what does it mean Is? Is... in unpacked ( expanded ) types pack but what is Is.
  3. Especially, which std::get fits from (1)-(8) (http://ift.tt/1MPYEjt)
  4. Why call_yadda_with_tuple gets std::index_sequence<Is...>. After all, this argument is nameless so it is useless. I suppose that it is connected with deduction types but I cannot see how does it help?

Aucun commentaire:

Enregistrer un commentaire