Why some Boost features do not need namespace prefixes

Consider this code (or a live example ):

#include <iostream> #include <boost/graph/adjacency_list.hpp> #include <boost/range/iterator_range.hpp> using std::cout; int main() { boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS> g; add_edge(0, 1, g); add_edge(1, 2, g); for(auto v : make_iterator_range(vertices(g))) { cout << v << " has " << degree(v, g) << " neighbor(s): "; for(auto w : make_iterator_range(adjacent_vertices(v, g))) cout << w << ' '; cout << '\n'; } return 0; } 

Why are the add_edge , make_iterator_range , vertices , degree and adjacent_vertices functions performed from the Boost library without the boost:: namespace prefix?

What is most unpleasant for me is that, depending on the situation, the prefix is ​​really needed. Here is an example where using a different chart structure leads to a compilation error, which can be fixed using the boost::make_iterator_range .

I looked at the BGL documentation for a bit, but found nothing on this. Is this my mistake or are some BGL headers polluting the global namespace? Is it design or is it a mistake?

+7
c ++ boost argument-dependent-lookup boost-graph
source share
1 answer

It is not associated with boost , but with any namespace .

With argument-dependent search (ADL), namespaces from the argument are added to the search for overloads.

So for example:

 add_edge(0, 1, g); 

g is from the boost namespace, so we are looking for add_edge also in the boost namespace.

+4
source share

All Articles