I have a question with respect to the following answer:
https://stackoverflow.com/a/15828866/2160256
As stated there, we cannot use range based for with BGL like this:
for(auto e : boost::edges(g))
// do something with e
However, here it states, that we can overload the begin() and end() functions that are required to use range based for semantics. So I tried:
template<class I>
I begin(std::pair<I,I>& p)
{ return p.first;}
template<class I>
I end(std::pair<I,I>& p)
{ return p.second;}
However, the compiler still complains:
error: no matching function for call to ‘
begin(std::pair<some_really_ugly_type,some_really_ugly_type>&)
’
What am I doing wrong? Does the name lookup not work? Or is this not possible after all? I also found this answer, which works, but shouldtn't it be possible with the begin/end free function overlods as well? Regards, Marti
BTW: I find it really tiresome to write
typename Graph::edge_iterator ebegin, eend;
std::tie(ebegin,eend) = boost::edges(_graph);
std::for_each(ebegin,eend,[&](const edge_descriptor& e){/*do something with e*/;});
UPDATE: C++17 should now allow the following :-)
auto [ebegin,eend] = boost::edges(_graph);