jeudi 16 avril 2020

std::vector with initial size explicitly set to 0

Will following C++ code be standard compliant if size remains 0?

std::size_t size = 0;
//... some code that may change size
auto foo = std::vector<int>(size);

Or do I have to resort to something like this:

std::size_t size = 0;
//... some code that may change size
auto foo = [size]() {
  if (size > 0) return std::vector<int>(size);
  else return std::vector<int>();
}();

Aucun commentaire:

Enregistrer un commentaire