You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The NWGraph graph concepts do not work with reference types. For example, the following code fails to compile:
#include<nwgraph/edge_list.hpp>// Fails: G = nw::graph::edge_list<...>& does not fulfill `nw::graph::edge_list_graph`template <nw::graph::edge_list_graph G>
voidfoo(G&&) {}
intmain(int argc, char** argv) {
nw::graph::edge_list<nw::graph::directedness::undirected, float> graph(0);
foo(graph);
return0;
}
Since graphs are specializations of ranges and will often represent data structures you don't want to copy, I think it will often be useful to use forwarding references (as above) with them. Note that std::ranges concepts like range, forward_range, and random_access_range do work with references.
(For counterpoint, the iterator concepts do not work with references, which has always annoyed me. However, iterators are supposed to be cheap to copy, so I suppose the standard library is implicitly encouraging us to pass iterators by value. However, I suppose you generally won't want to pass graphs by value.)
The two issues preventing references from working are:
vertex_id_t This could be fixed by changing the definition on line 37 of graph_traits.hpp to
std::copyable You could also add a std::remove_cvref_t<G> on line 57 of graph_concepts.hpp. However, I'm not sure that I'm convinced graphs always need be copyable in the first place? I suppose both a container, which owns the data, as well as a copy-constructible view, would be copyable, although copying means different things in these two cases. I guess you're really disabling move-only views from being graphs here?
The text was updated successfully, but these errors were encountered:
The NWGraph graph concepts do not work with reference types. For example, the following code fails to compile:
Since graphs are specializations of ranges and will often represent data structures you don't want to copy, I think it will often be useful to use forwarding references (as above) with them. Note that
std::ranges
concepts likerange
,forward_range
, andrandom_access_range
do work with references.(For counterpoint, the iterator concepts do not work with references, which has always annoyed me. However, iterators are supposed to be cheap to copy, so I suppose the standard library is implicitly encouraging us to pass iterators by value. However, I suppose you generally won't want to pass graphs by value.)
The two issues preventing references from working are:
vertex_id_t
This could be fixed by changing the definition on line 37 ofgraph_traits.hpp
tostd::copyable
You could also add astd::remove_cvref_t<G>
on line 57 ofgraph_concepts.hpp
. However, I'm not sure that I'm convinced graphs always need be copyable in the first place? I suppose both a container, which owns the data, as well as a copy-constructible view, would be copyable, although copying means different things in these two cases. I guess you're really disabling move-only views from being graphs here?The text was updated successfully, but these errors were encountered: