Question & Answer
Question
When I try compiling the following construct the compilation fails while processing the xmemory standard header file. Is this the correct behaviour?
#include
Answer
The behaviour is correct as, according to the ISO C++ Standard, creating containers of const objects is not allowed. Section 23.1:3 indicates that the type of objects stored in a container must meet the requirements of CopyConstructible (20.1.3) and Assignable types. Assignable is defined in Table 64 in the same section as an object that can be assigned value, which means that object cannot be a const.
On the other hand, Table 31 in section 20.1.5 indicates that type T in std::allocator<T> can be of any type. This obviously contradicts the previously referenced section 23.1:3. The C++ Standard Committee has determined that section 23.1:3 is correct, and that Table 31 is in fact wrong in the aforementioned assumption. The C++ standard library defect 274 has been created to correct this inconsistency in the next C++ Standard release.
Click below for a related FAQ which describes the same error using a different test case:
Related Information
Historical Number
06003
Was this topic helpful?
Document Information
Modified date:
08 August 2018
UID
swg21162689