jeudi 27 septembre 2018

universal reference within lambda capture [duplicate]

This question already has an answer here:

I have a function with universal reference:

template<typename T>
void Func(T&& foo) {
  // within this function, I have a lambda function
  auto someFunc = [&foo] {                    <---- is this the right way to do it?
      callIntoAnotherFunction(std::forward<T>(foo));
  }
}

Wondering if the way to use reference in the lambda is correct or not. Also what does it mean? Do I always pass into the lambda by reference? What if foo is a r-val reference then?

Aucun commentaire:

Enregistrer un commentaire