Bonita Montero
unread,Sep 23, 2020, 7:58:53 AM9/23/20You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Am 23.09.2020 um 12:16 schrieb Frederick Gotham:
> #include <type_traits> /* remove_cv, remove_reference */
> #include <algorithm> /* sort */
>
> template<class InputIt1, class InputIt2, class OutputIt>
> OutputIt set_intersection_unsorted(InputIt1 first1, InputIt1 last1,
> InputIt2 first2, InputIt2 last2,
> OutputIt d_first)
> {
> /* The iterators might be plain ol' pointers, e.g. char* */
> /* To keep compatibility with C++11, don't use 'remove_cv_t' */
>
> typedef typename std::remove_cv< typename std::remove_reference<decltype(*first1)>::type >::type type1;
> typedef typename std::remove_cv< typename std::remove_reference<decltype(*first2)>::type >::type type2;
>
> vector<type1> container1(first1,last1);
> vector<type2> container2(first2,last2);
>
> std::sort(container1.begin(), container1.end());
> std::sort(container2.begin(), container2.end());
>
> return std::set_intersection(container1.begin(), container1.end(),
> container2.begin(), container2.end(),
> d_first);
> }
It looks okay to me, but why is the function called set_intersection
*_unsorted* ? Becaus the result of std::set_intersection itself is
sorted.