P
P
Pawlowitsch2021-11-28 20:52:53
C++ / C#
Pawlowitsch, 2021-11-28 20:52:53

Can't find multiset intersections, what's the problem?

I need to find the intersections of two multisets, each of which is inside a vector.
Here is the part of the code where I did it:

unordered_multiset <char> intersect; //множество для результата пересечения
unordered_multiset <char> first;
unordered_multiset <char> second;
for (int i = 0; i < Sentence.size(); i++) { //Sentence - это vector <unordered_multiset<char>>
  for (int j = 0; j < Dictionary.size(); j++) { //Dictionary  - это тоже vector <unordered_multiset<char>>
    first = Sentence[i];
    second = Dictionary[j];
    set_intersection(first.begin(), first.end(), second.begin(), second.end(), intersect.begin());


The program did not compile and gave an error: C3892 _UDest: Cannot assign values ​​to a variable that is declared as a constant.

I replaced in
set_intersection(first.begin(), first.end(), second.begin(), second.end(), intersect.begin());

intersect.begin()The program compiles, but stops at inserter(intersect, intersect.begin())

the same line and says: An invalid parameter was passed to a function for which invalid parameters cause a fatal error.

As I understand it, the fifth parameter in set_intersection should be OutPutIterator, but apparently .begin() returns InPutIterator.

As a result, having climbed all the sites and forums, I still did not understand what the mistake was.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2021-11-28
@Pawlowitsch

The problem is that unordered_set iterators are of type ForwardIterator. The set_intersection options that expect an iterator like this for the result also want an ExecutionPolicy.
But even if you change the type of the intersect so that the answer can be inserted there, your code will not work, because set_intersection waits for ordered intervals. Does unorderedthe name of the containers bother you?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question