[ptr_container] Can't store a pointer to const in multimap?

Please consider the following code: #include "boost/ptr_container/ptr_map.hpp" int main() { typedef boost::ptr_multimap<char, const int> M; M m; char c = 'c'; int* j = new int(7); m.insert(c, j); return 0; } The gcc 4.3.3 compiler fails to compiler the above code. Am I doing something wrong by inserting a non-const? Can't I store a pointer to const in the multimap? try.cpp: In function ‘int main()’: try.cpp:8: error: expected primary-expression before ‘=’ token /usr/include/c++/4.3/bits/stl_pair.h: In constructor ‘std::pair<_T1, _T2>::pair(const std::pair<_U1, _U2>&) [with _U1 = char, _U2 = const int*, _T1 = const char, _T2 = void*]’: boost/boost_1_39_0/boost/ptr_container/ptr_map_adapter.hpp:765: instantiated from ‘typename boost::ptr_container_detail::ptr_map_adapter_base<T, VoidPtrMap, CloneAllocator, Ordered>::iterator boost::ptr_multimap_adapter<T, VoidPtrMultiMap, CloneAllocator, Ordered>::insert_impl(const typename boost::ptr_container_detail::ptr_map_adapter_base<T, VoidPtrMap, CloneAllocator, Ordered>::key_type&, typename boost::ptr_container_detail::ptr_map_adapter_base<T, VoidPtrMap, CloneAllocator, Ordered>::mapped_type) [with T = const int, VoidPtrMultiMap = std::multimap<char, void*, std::less<char>, std::allocator<std::pair<const char, void*> > >, CloneAllocator = boost::heap_clone_allocator, bool Ordered = true]’ boost/boost_1_39_0/boost/ptr_container/ptr_map_adapter.hpp:799: instantiated from ‘typename boost::ptr_container_detail::ptr_map_adapter_base<T, VoidPtrMap, CloneAllocator, Ordered>::iterator boost::ptr_multimap_adapter<T, VoidPtrMultiMap, CloneAllocator, Ordered>::insert(typename boost::ptr_container_detail::ptr_map_adapter_base<T, VoidPtrMap, CloneAllocator, Ordered>::key_type&, typename boost::ptr_container_detail::ptr_map_adapter_base<T, VoidPtrMap, CloneAllocator, Ordered>::mapped_type) [with T = const int, VoidPtrMultiMap = std::multimap<char, void*, std::less<char>, std::allocator<std::pair<const char, void*> > >, CloneAllocator = boost::heap_clone_allocator, bool Ordered = true]’ try.cpp:9: instantiated from here /usr/include/c++/4.3/bits/stl_pair.h:106: error: invalid conversion from ‘const void*’ to ‘void*’ I also tried but failed with const casting j before insertion.

Amit Kumar wrote On Monday, June 15, 2009 1:33 PM
Please consider the following code:
#include "boost/ptr_container/ptr_map.hpp"
int main() { typedef boost::ptr_multimap<char, const int> M;
M m; char c = 'c';
int* j = new int(7);
m.insert(c, j);
return 0; }
The gcc 4.3.3 compiler fails to compiler the above code. Am I doing something wrong by inserting a non-const? Can't I store a pointer to const in the multimap?
I don't know anything about that particular container, but I can well imagine that you've declared the value type to be immutable, so is it a surprise you can't change one? _____ Rob Stewart robert.stewart@sig.com Software Engineer, Core Software using std::disclaimer; Susquehanna International Group, LLP http://www.sig.com IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

Amit Kumar skrev:
Please consider the following code:
#include "boost/ptr_container/ptr_map.hpp"
int main() { typedef boost::ptr_multimap<char, const int> M;
M m; char c = 'c';
int* j = new int(7);
m.insert(c, j);
return 0; }
The gcc 4.3.3 compiler fails to compiler the above code. Am I doing something wrong by inserting a non-const? Can't I store a pointer to const in the multimap?
This is currently unsupported, though I might get it to work. I'll put it on my todo list. -Thorsten
participants (3)
-
Amit Kumar
-
Stewart, Robert
-
Thorsten Ottosen