title: BGL custom graph connected_components
body: <p>I'm trying to use the <code>connected_components</code> algorithm of boost graph library. I have a data structure defining such a graph in a different format and I want to avoid copying the graph to the BGL's graph types, such as <code>adjacency_list</code>. Therefore I use the <code>graph_traits</code> to let BGL know how to operate directly on my graph structure. Below is a simplified example exhibiting the same problem I face with the actual data: </p>
  
  <pre><code>#include &lt;vector&gt;
  #include &lt;map&gt;
  #include &lt;boost/graph/graph_traits.hpp&gt;
  #include &lt;boost/graph/connected_components.hpp&gt;
  
  namespace myns {
      struct MyGraph {
          using VertsContainer = std::vector&lt;std::string&gt;;
          using Edge = std::pair&lt;std::string, std::string&gt;;
          using EdgesContainer = std::vector&lt;Edge&gt;;
  
          VertsContainer verts;
          EdgesContainer edges;
  
          void get_connected_components();
      };
  }
  
  
  namespace boost
  {
      template&lt;&gt;
      struct graph_traits&lt;myns::MyGraph&gt; {
          /////////////////////////////////
          // Graph concept
          /////////////////////////////////
          using vertex_descriptor = myns::MyGraph::VertsContainer::value_type;
          using edge_descriptor = myns::MyGraph::EdgesContainer::value_type;
  
          using directed_category = boost::undirected_tag;
          using edge_parallel_category = boost::disallow_parallel_edge_tag;
  
          struct traversal_category : boost::vertex_list_graph_tag, boost::incidence_graph_tag {};
  
          /////////////////////////////////
          // Incidence graph concept
          /////////////////////////////////
          using out_edge_iterator = myns::MyGraph::EdgesContainer::const_iterator;
          using degree_size_type = std::size_t;
  
          // out_edges(v, g)
          // source(e, g)
          // target(e, g)
          // out_degree(v, g)
  
          /////////////////////////////////
          // Adjacency graph concept
          /////////////////////////////////
          using adjacency_iterator = myns::MyGraph::VertsContainer::const_iterator;
  
          // adjacent_vertices(v, g)
  
          /////////////////////////////////
          // Vertex list graph concept
          /////////////////////////////////
          using vertex_iterator = myns::MyGraph::VertsContainer::const_iterator;
          using vertices_size_type = std::size_t;
  
          // vertices(g)
          // num_vertices(g)
      };
  
  } // namespace boost 
  
  namespace myns
  {
      boost::graph_traits&lt;myns::MyGraph&gt;::vertex_descriptor
          source(const boost::graph_traits&lt;myns::MyGraph&gt;::edge_descriptor&amp; e, const myns::MyGraph&amp; g)
      {
          return e.first;
      }
  
      boost::graph_traits&lt;myns::MyGraph&gt;::vertex_descriptor
          target(const boost::graph_traits&lt;myns::MyGraph&gt;::edge_descriptor&amp; e, const myns::MyGraph&amp; g)
      {
          return e.second;
      }
  
      std::pair&lt;boost::graph_traits&lt;myns::MyGraph&gt;::out_edge_iterator, boost::graph_traits&lt;myns::MyGraph&gt;::out_edge_iterator&gt;
          out_edges(const boost::graph_traits&lt;myns::MyGraph&gt;::vertex_descriptor&amp; v, const myns::MyGraph&amp; g)
      {
          return{g.edges.begin(), g.edges.end()};
      }
  
      boost::graph_traits&lt;myns::MyGraph&gt;::degree_size_type
          out_degree(const boost::graph_traits&lt;myns::MyGraph&gt;::vertex_descriptor&amp; v, const myns::MyGraph&amp; g)
      {
          return g.edges.size();
      }
  
      std::pair&lt;boost::graph_traits&lt;myns::MyGraph&gt;::adjacency_iterator, boost::graph_traits&lt;myns::MyGraph&gt;::adjacency_iterator&gt;
          adjacent_vertices(const boost::graph_traits&lt;myns::MyGraph&gt;::vertex_descriptor&amp; v, const myns::MyGraph&amp; g)
      {
          return{g.verts.begin(), g.verts.end()};
      }
  
      std::pair&lt;boost::graph_traits&lt;myns::MyGraph&gt;::vertex_iterator, boost::graph_traits&lt;myns::MyGraph&gt;::vertex_iterator&gt;
          vertices(const myns::MyGraph&amp; g)
      {
          return{g.verts.begin(), g.verts.end()};
      }
  
      boost::graph_traits&lt;myns::MyGraph&gt;::vertices_size_type
          num_vertices(const myns::MyGraph&amp; g)
      {
          return g.verts.size();
      }
  
  } // namespace myns
  
  static void _test_concepts()
  {
      BOOST_CONCEPT_ASSERT((boost::IncidenceGraphConcept&lt;myns::MyGraph&gt;));
      BOOST_CONCEPT_ASSERT((boost::VertexListGraphConcept&lt;myns::MyGraph&gt;));
  }
  
  void myns::MyGraph::get_connected_components()
  {
      _test_concepts();
  
      auto connectedComponentsMap = std::map&lt;std::string, int&gt;{};
      boost::associative_property_map&lt; std::map&lt;std::string, int&gt; &gt; comp_prop_map(connectedComponentsMap);
  
      boost::connected_components(*this, comp_prop_map);
  }
  
  int main()
  {
      myns::MyGraph().get_connected_components();
  }
  </code></pre>
  
  <p>The error I get is:</p>
  
  <pre><code>In file included from /usr/local/include/boost/graph/graph_traits.hpp:18:
  /usr/local/include/boost/mpl/eval_if.hpp:38:26: error: no type named 'type' in 'boost::no_property'
      typedef typename f_::type type;
          ~~~~~~~~~~~~~^~~~
  </code></pre>
  
  <p>Full error message and live code <a href="http://coliru.stacked-crooked.com/a/6533efa7993e69be" rel="nofollow">here</a>.</p>
  
  <p>What am I missing?</p>