JohnCoconut / boost_graph_cookbook_1

A well-connected C++14 Boost.Graph tutorial
http://richelbilderbeek.nl/CppBoostGraphTutorial.htm
GNU General Public License v3.0
0 stars 0 forks source link

Algorithm "has_vertex_with_name" and "find_first_vertex_with_name" (84 and 86) #6

Open JohnCoconut opened 6 years ago

JohnCoconut commented 6 years ago

The return value of these two algorithms should be an iterator iter to vertices of graph.

Use iter != vip.second to check has_vertex_with_name.

And dereference it to get vertex descriptor.

It's consistent with STL algorithm in this way.

richelbilderbeek commented 6 years ago

Thanks for your -as one might call it now- your thorough code review :+1:

We agree that find_first_vertex_with_name should return an iterator, like std::find.

I fail to see why has_vertex_with_name should return an iterator as well. If one asks 'Does X have a Y?', the reply is expected to be 'true', 'false' (or something more human). As there is no std::has_ algorithm, which one do you refer to?

Keep up the great work!

JohnCoconut commented 6 years ago

@richelbilderbeek Sorry I wasn't clear.

I am suggesting, function has_vertex_with_name calls find_first_vertex_with_name. Something like this (not real code),

#include "find_first_vertex_with_name.hpp"

bool has_vertex_with_name(const Name& name, const Graph& g)
{
  auto vip = vertices(g);
  auto iter = find_first_vertex_with_name(name, g);
  return iter != vip.second;
}
richelbilderbeek commented 6 years ago

Totally agree! I'd enjoy getting rid if the code duplication in this repo.

(just checked Travis, still fails :disappointed:)