Note that there are some explanatory texts on larger screens.

plurals
  1. POset_difference and set_intersection simultaneously
    primarykey
    data
    text
    <p>I'm wondering if there is any facility in the standard library to simultaneously compute the set intersection and set difference between two sorted ranges. Something with a signature along the lines of:</p> <pre><code>template &lt;class Input1, class Input2, class Output1, class Output2, class Output3&gt; Output3 decompose_sets (Input1 first1, Input1 last1, Input2 first2, Input2 last2, Output1 result1, Output2 result2, Output3 result3 ); </code></pre> <p>Such that after a call to <code>decompose sets</code>, <code>result1</code> contains all the elements in <code>[first1,last1)</code> which are not in <code>[first2,last2)</code>, <code>result2</code> contains all the elements in <code>[first2,last2)</code> which are not in <code>[first1,last1)</code>, and <code>result3</code> contains all element which are common in <code>[first1,last1)</code> and <code>[first2,last2)</code>.</p> <p>The example implementations of <a href="http://www.cplusplus.com/reference/algorithm/set_difference/" rel="nofollow"><code>set_difference</code></a> and <a href="http://www.cplusplus.com/reference/algorithm/set_intersection/" rel="nofollow"><code>set_intersection</code></a> from cplusplus.com seem like they can help me to create an efficient implementation which performs only one scan instead of three. If it's in the standard library, though, I'd hate to reinvent the wheel.</p> <p>Example, by request:</p> <p>Given two sets a={0, 1, 2, 3, 4} and b={2, 4, 5, 6} then I would like to build the following three sets:</p> <ul> <li>only_a = {0,1,3}</li> <li>only_b = {5,6}</li> <li>common = {2,4}</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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