0

This code compiles on recent gcc and clang:

#include <iterator>
#include <vector>

int main(int argc, char** argv)
{
   std::vector<int> v(20);
   fill(begin(v), end(v), 0);
   return EXIT_SUCCESS;
}

But surely it SHOULD NOT.

Don't I need std::fill(std::begin(v), std::end(v), 0);?

What's changed? Why are these functions in the global namespace?

Zendel
  • 485
  • 3
  • 14
  • 1
    Headers are allowed to include other headers. You just can't rely on it. – Jesper Juhl Dec 01 '18 at 15:12
  • Nothing changed. ADL is pretty old. Though you'd probably get the error you expect if you build with optimizations. – StoryTeller - Unslander Monica Dec 01 '18 at 15:35
  • It all makes perfect sense now. Never bothered to learn what ADL was, other than how to use std::swap properly. Kinda wish it wasn't a language feature, or it worked differently. Definitely see the potential for head scratching bugs. – Zendel Dec 02 '18 at 17:50

0 Answers0