This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of NAD status.

2161. const equivalence of std::map

Section: 26.4 [associative], 26.5 [unord] Status: NAD Submitter: Bjarne Stroustrup Opened: 2012-06-18 Last modified: 2017-02-03

Priority: 2

View all other issues in [associative].

View all issues with NAD status.


As described in the reflector discussion c++std-core-21860 consider the following example:

map<const int, int> mci{};
map<int, int> mi = mci; // ??
mci[1] = 2;
mi[1] = 2;

Should it be required that the marked initialization is well-formed? As a possible solution this could be realized by an alias template:

template <class K, class T>
struct OriginalMap { […] };

template <class K, class T>
using ImprovedMap = OriginalMap<const K, T>;

[2016-08 Chicago]

Recommend NAD. No other container supports conversion from different container specializations, so adding support directly might be more surprising than the omission.

We would welcome papers on the convertibility of containers of different element types directed to the LEWG in the future.

Proposed resolution: