set_symmetric_difference with map holders

I want to do the symmetric difference between two sets, each represented by a map. I also using a mex function so it can be handled in matlab. It is read by the mex function two 2xk matrices from matlab and populate the input maps m and p. I am not showing that. The problem is with the function that does the symmetric difference. Here is some code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "math.h"
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <map>
#include <limits>
#include <utility>
#include <assert.h>

#ifdef _CHAR16T   // I have matlab 2010a so I need to redefine chart_t
#define CHAR16_T
#endif
#include "mex.h"
#include "matrix.h

using namespace std;
void bla(//inputs
        map<int,int> const& m,
	map<int,int> const& p, 
	//output
	Path newM)
{
map<int,int>::iterator n; 
n=set_symmetric_difference(m.begin(),m.end(),p.begin(),p.end(),newM.begin()); 
}


Then I run the mex file using matlab 2010a but I am getting the following errors.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\utility(216) : error C2166: l-value specifies const object 
        C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\utility(215) : while compiling class template member function 'std::pair<_Ty1,_Ty2> &std::pair<_Ty1,_Ty2>::operator =(const std::pair<_Ty1,_Ty2> &)' 
        with 
        [ 
            _Ty1=const int, 
            _Ty2=int 
        ] 
        getBlah.cxx(39) : see reference to class template instantiation 'std::pair<_Ty1,_Ty2>' being compiled 
        with 
        [ 
            _Ty1=const int, 
            _Ty2=int 
        ] 
 
  C:\PROGRA~1\MATLAB\R2010A\BIN\MEX.PL: Error: Compile of 'getBlah.cxx' failed. 
 
??? Error using ==> mex at 222
Unable to complete successfully.
 


Looks like there is a problem with map for m and p because it make the key of the mapping const_int while the value is int and the type in the map is map<int, int>.
I will really apreciate any help.
The key values for map are const, since you should not change them (this would ruin the sorting of the map). You could easily write the symmetric difference function yourself. Assuming the two maps do have like values for like keys:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
unique_ptr<map<int,int>> map_symmetric_difference (const map<int,int>& Map_A,const map<int,int>& Map_B)
{
unique_ptr<map<int,int>> Out(new map<int,int>);
map<int,int>::const_iterator it_A=Map_A.begin();
map<int,int>::const_iterator it_B=Map_B.begin();
map<int,int>::const_iterator lim_A=Map_A.end();
map<int,int>::const_iterator lim_B=Map_B.end();
while (!(it_A==lim_A && it_B==lim_B))
{
if (it_A==lim_A) {Out->insert(*it_B++);}
else if (it_B==lim_B) {Out->insert(*it_A++);}
else if (it_A->first<it_B.first){Out->insert(*it_A++);}
else if (it_B->first<it_A.first){Out->insert(*it_B++);}
else {++it_A;++it_B;}
}
return Out;
}

Topic archived. No new replies allowed.