Allow use of grid_graph without "using namespace boost"#91
Allow use of grid_graph without "using namespace boost"#91murraycu wants to merge 3 commits intoboostorg:developfrom
Conversation
Implementing the get() functions as friend functions in the class declaration just puts them in the global namespace, or at least doesn't make them callable from the boost:: namespace.
Implementing these functions as friend functions in the class declaration just puts them in the global namespace, or at least doesn't make them callable from the boost:: namespace.
Implementing these functions as friend functions in the class declaration just puts them in the global namespace, or at least doesn't make them callable from the boost:: namespace.
|
I'm helping out with the PR backlog. Looks like you have a feature addition, no test, and no new examples will be needed. Users can just use 'use' semantics. I'd like to have a test, but also see appropriate changes in the examples and documentation. The change you are proposing is actually larger. This is to let you know and help me prioritize PR's. |
|
@murraycu Can you rebase your PR on devel? |
|
I don't quite get what this PR is trying to achieve, since |
|
For example, with using boost::minstd_rand;
using boost::grid_graph;
using boost::graph_traits;
using boost::lexical_cast;then the ADL works to find @jzmaddock I'm pretty sure, unless I've missed something, that this PR is based on a misunderstanding and thus not actually achieving what it sets out to. |
|
Can the OP post a use case that doesn't work at present? |
|
The OP seems to be MIA. |
|
[snip]
I'd like the API to be usable without any "using", so without either "using boost" or "using boost::somethingelse". |
|
@murraycu That would mean putting boost into the global namespace. Not even the standard library does that and it is far for common to use than boost. That isn't a reason for such a change. |
I don't think that was the intended meaning since such a change would be radical and disproportionate. That should work via ADL. And the change made in this PR does not appear to have any bearing on ADL, since the look-up rules for As for Murray, does that make sense? I might be wrong and I can't actually experiment with the code today. |
|
Actually looking at this, I believe the PR is valid - though whether it matters is another thing. The OP is correct that these non-members cannot be called via But.... the documentation is clear that an unqualified to and then everything built just fine. So... IMO this is low priority, but harmless enough. I would want to remove the explicit boost:: prefixes added to the examples/tests though as they're not required - and we should test that they're not required as that's the documented syntax. |
|
A couple of other points:
|
|
OK, I can agree that removing friend access from functions that don't require it is an improvement, such as the two overloads of But what is the point of un-inlining the definition of friend functions that are going to remain friends? |
This is really about whether people should be able to use the BGL API without putting "using namespace boost" in their code. I think they should, and they can with most of the API, but not all - for instance, boost::grid_graph.
Currently, removing "using namespace boost", and using the "boost::" prefix instead, causes the following compiler errors, because these functions are actually member methods of the grid_graph class, not functions in the boost namespace.
Normally, when we call, for instance, just num_vertices(graph), instead of boost::num_vertices(graph), the compiler finds the member method via argument dependent lookup.
As you can see by these example commits, fixing this involves some tedious code outside of the class. Maybe you see a better way to do it. If this is the only way then I still think it's worth it.
This would also be fixed by Bjarne Stroustrup's Unified Call proposal:
https://isocpp.org/blog/2016/02/a-bit-of-background-for-the-unified-call-proposal
but that doesn't seem likely to happen any time soon.