mardi 8 janvier 2019

Assignment without copy in std move

I have a util function which returns a map

std::map getFooMap() {
  std::map foo;
  // ... populate the map
  return foo;
}

From the caller side, I want to assign the map to a data field of some object. I can do:

dest.data = getFooMap()

Will this be faster than the following?

auto temp = getFooMap();
dest.data = std::move(temp);

I think this should be as I avoid one extra copy?

Aucun commentaire:

Enregistrer un commentaire