Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using boost::depth_first_search with Visitor

As the title suggests, I'm using boost::depth_first_search and using a Visitor (inheriting from boost::default_dfs_visitor) to implement some algorithm.

However, during the algorithm's run, I want to save some information in the visitor, to be queried later. However, the information is erased after the DFS is done, so I assume it uses a copy. Other than just using pointers for all private variables, is there a way to prevent this and make boost use my copy?

like image 266
Amir Rachum Avatar asked Dec 16 '25 16:12

Amir Rachum


1 Answers

You could try passing your visitor wrapped in a boost::reference_wrapper.

Edit - teh codez

YourVisitorClass your_visitor;
boost::depth_first_search(your_graph, boost::ref(your_visitor), 
                          your_color_map);

boost::ref(your_visitor) returns a boost::reference_wrapper<YourVisitorClass>. When depth_first_search creates a copy of that arguments, it will copy the reference_wrapper instead of the visitor object. Copies of the reference will refer to the same instance as the original.

like image 83
Björn Pollex Avatar answered Dec 19 '25 06:12

Björn Pollex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!