Like many people these days I have been trying the different features that C++11 brings. One of my favorites is the “range-based for loops”.

I understand that:

for(Type& v : a) { ... }

Is equivalent to:

for(auto iv = begin(a); iv != end(a); ++iv)
  Type& v = *iv;

And that begin() simply returns a.begin() for standard containers.

But what if I want to make my custom type “range-based for loop”-aware?

Should I just specialize begin() and end()?

If my custom type belongs to the namespace xml, should I define xml::begin() or std::begin() ?

In short, what are the guidelines to do that?