microsoft / microsoft/STL

<xmemory>: Consider clarifying the static_assert for Container<const T>

Open
#180 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
C++
Stars
11.1k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

We emit a static_assert when a user attempts to say vector<const T> and so forth. Somewhat confusingly, this is emitted at the std::allocator layer:

https://github.com/microsoft/STL/blob/957fe99f41748b80c3108447e5dd5ce2be962f4e/stl/inc/xmemory#L737-L741

The Standard's wording is distressingly unclear; once upon a time, allocator was indeed the best way to see that Container<const T> was forbidden (because it would overload allocator::address() improperly). Now this appears to be indirectly specified through the allocator requirements.

Ideally, the Standard would be clarified to obviously forbid Container<const T>. Until then, we should consider clarifying this static_assert, and possibly move it into each container. (I hope users aren't saying map<const int, const int> and so forth.)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the static_assert in stl/inc/xmemory at lines 737-741 and review the issue's linked context about Container. Determine whether the diagnostic should be clarified or moved into individual containers, and establish the intended behavior for cases such as map<const int, const int>.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.