Note that there are some explanatory texts on larger screens.

plurals
  1. POCompare in a deque of tuples c++
    text
    copied!<p>I have this deque of tuples:</p> <pre><code> deque&lt;boost::tuple&lt;ppa::Node*, ppa::Node*, ppa::Node*, bool&gt; &gt; deque_wait; </code></pre> <p>And I want to be able to compare the elements one by one with this other:</p> <pre><code>deque&lt;boost::tuple&lt;ppa::Node*, ppa::Node*, ppa::Node*, bool&gt; &gt; deque_done; </code></pre> <p>This is because I want to see what nodes are done and then have a thread pick the next on the list and do something with that, the code I have is this:</p> <p>Trying to do something like this:</p> <pre><code> bool tuple_compare(boost::tuple&lt;ppa::Node*, ppa::Node*, ppa::Node*, bool&gt; &amp;tuple_to_check) { for(int i = 0; i &lt; deque_wait.size(); i++) { boost::tuple&lt;ppa::Node*, ppa::Node*, ppa::Node*, bool&gt; tuple_compare = deque_wait.at(i); ppa::Node *father = boost::get&lt;0&gt;(tuple_compare); ppa::Node *son = boost::get&lt;0&gt;(tuple_compare); ppa::Node *second_son = boost::get&lt;2&gt;(tuple_compare); bool has_seq = boost::get&lt;3&gt;(tuple_compare); cout &lt;&lt; "checking " &lt;&lt; boost::get&lt;1&gt;(tuple_to_check)-&gt;get_name() &lt;&lt; " " &lt;&lt; boost::get&lt;2&gt;(tuple_to_check)-&gt;get_name() &lt;&lt; " " &lt;&lt; boost::get&lt;0&gt;(tuple_compare)-&gt;get_name() &lt;&lt; endl; } return true; </code></pre> <p>}</p> <p>Thread func:</p> <pre><code> void wait_function(void) { try { } catch (boost::lock_error &amp;le) { cout &lt;&lt; le.what() &lt;&lt; " from " &lt;&lt; boost::this_thread::get_id() &lt;&lt; endl; } } </code></pre> <p>I know that mutex are needed, I have planned those, for now I just need to know how to compare the elements of the deque with the other to see if they fulfill certain conditions and running them, the compare right now is being used with the sort function like:</p> <pre><code>sort(deque_wait.begin(), deque_wait.end(), tuple_compare); </code></pre> <p>Because I though that I could use this func to compare the 2 deques, so in summary what I want to do is to compare the first element of deque_done with all the wait and if the conditions are fulfilled change the bool to true, they are different done and wait, the reason I want to check them is because this a tree like structure has a parent and 2 sons so each tuple is that, a parent and 2 sons and I need to see which sons have a sequence to put it ready to do and which are not so to have a thread come and pick it up, it does not matter if another thing like a vector or another deque is needed, so in this case price is not important, thanks. (:</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload