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:
#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
usingnamespace 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 classtemplate member function 'std::pair<_Ty1,_Ty2> &std::pair<_Ty1,_Ty2>::operator =(const std::pair<_Ty1,_Ty2> &)'
with
[
_Ty1=constint,
_Ty2=int
]
getBlah.cxx(39) : see reference to classtemplate instantiation 'std::pair<_Ty1,_Ty2>' being compiled
with
[
_Ty1=constint,
_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: