0

I'm porting my code which written in cpp to support ARM9 using ADS 1.2 compiler,but after porting the below code gives error while compiling for ARM11 using RVCT2.2 compiler, this is the sample code

list<int,allocator<int> > mystack;
map<int*,list<int,allocator<int> >,less<int*>,allocator<pair<int*,list<int,allocator<int> > > > > mymap;
mymap[addr] = mystack;
Error 1:Error:  #167:argument of type "std::allocator<std::pair<int *,
std::list<int, std::allocator<int>>>>::const_pointer" is incompatible with
parameter of type "std::allocator<std::pair<int *, std::list<int, 
std::allocator<int>>>>::pointer"

Error 2:Error:  #434: a reference of type 
"__rw::__rw_tree_iter<__rw::__rb_tree<std::map<int *, std::list<int, 
std::allocator<int>>, std::less<int *>, std::allocator<std::pair<int *, 
std::list<int, std::allocator<int>>>>>::key_type, std::map<int *, 
std::list<int, std::allocator<int>>, std::less<int *>, 
std::allocator<std::pair<int *, std::list<int, 
std::allocator<int>>>>>::value_type,  (not const-qualified) cannot be 
initialized with a value of type "std::map<int *, std::list<int, 
std::allocator<int>>, std::less<int *>, std::allocator<std::pair<int *, 
std::list<int, std::allocator<int>>>>>::value_type"
          return _C_node->_C_value();
NathanOliver
  • 171,901
  • 28
  • 288
  • 402
Jay
  • 3
  • 1

1 Answers1

0

The problem you have is the allocator for std::map needs to be pair of

std::pair<const Key, T>

Right not you have

pair<int*,list<int,allocator<int> > >

Which is not the same as you do not have the Key const qualified. It should be

pair<int* const,list<int,allocator<int> > >

Since you are using the standard allocator there is no reason to specify the allocator. You can just use

list<int> mystack;
map<int*,list<int>> mymap;
mymap[addr] = mystack;

And the list will default to using a std::allocator<int> and the map will default to using std::less<int*> and std::allocator<int * const, std::list<int>>

Also not that std::less<int*> do not compare the values the int* points to but instead it compares the address. If you need the former you need to write your own comparison object to do that.

NathanOliver
  • 171,901
  • 28
  • 288
  • 402
  • ADS 1.2 compiler doesn't support namespace,hence I can't use std::map and also I get the same error when I declare the pair as "pair > >". – Jay Jul 15 '16 at 16:12
  • @Jay If you manually specify it it should be `pair > >` as you have a `const` pointer to an `int` not a pointer to a `const int` – NathanOliver Jul 15 '16 at 16:23
  • @Jay No problem. I still get tripped up from time to time on where to place the `const`. – NathanOliver Jul 15 '16 at 16:39