0

Both this code:

#include <algorithm>
#include <iostream>
#include <iterator>
#include <utility>
#include <vector>

int main() {
  std::vector<int> v;

  std::exchange(v, {1, 2, 3, 4, 5});

  copy(cbegin(v), cend(v) - 1, std::ostream_iterator<int>(std::cout, ", "));
  std::cout << *rbegin(v) << "\n\n";

  return 0;
}

and this code:

#include <algorithm>
#include <iostream>
#include <iterator>
#include <utility>
#include <vector>

int main() {
  std::vector<int> v;

  std::exchange(v, {1, 2, 3, 4, 5});

  std::copy(std::cbegin(v), std::cend(v) - 1, std::ostream_iterator<int>(std::cout, ", "));
  std::cout << *std::rbegin(v) << "\n\n";

  return 0;
}

can be compiled (in C++14 and C++17) successfully and do the same job. But I wonder why I can omit std:: as well as in what circumstance?

Jarod42
  • 203,559
  • 14
  • 181
  • 302
Gamcheong
  • 41
  • 2

0 Answers0