According to the documentation for multiset for instance see http://www.cplusplus.com/reference/set/multiset/insert/. It should be possible to insert a const value. In my example the multiset is a collection of pointers, but when I try to insert a const pointer I get an error.
template<typename Key>
struct node_key: public node_base {
node_key(Key k): _key(k) {}
virtual ~node_key() {}
const Key& key() const { return _key;}
protected:
Key _key;
void _copy_key(node_key<Key> *n) const { n->_key=_key;}
};
template <typename Compare>
struct ptr_less_key {
ptr_less_key() : _comp() {}
virtual ~ptr_less_key() {}
template <typename Pointer>
bool operator()(const Pointer& a, const Pointer& b) const { return _comp(a->key(), b->key()); }
Compare _comp;
};
int main() {
typedef node_key<int>* keyp;
std::multiset<keyp,ptr_less_key<std::less<int>>> x;
node_key<int> k(5);
const node_key<int> *p=&k;
x.insert(p); //this fails
return 0;
}