3330. Include <compare> from most library headers

Section: 17.12.2 [coroutine.syn], 19.5.2 [system.error.syn], 22.2.1 [utility.syn], 22.4.2 [tuple.syn], 22.5.2 [optional.syn], 22.6.2 [variant.syn], 20.2.2 [memory.syn], 17.7.6 [type.index.synopsis], 27.4.2 [string.syn], 27.3.2 [string.view.synop], 23.3.2 [array.syn], 23.3.4 [deque.syn], 23.3.6 [forward.list.syn], 23.3.8 [list.syn], 23.3.10 [vector.syn], 23.4.2 [associative.map.syn], 23.4.5 [associative.set.syn], 23.5.2 [unord.map.syn], 23.5.5 [unord.set.syn], 23.6.2 [queue.syn], 23.6.5 [stack.syn], 24.2 [iterator.synopsis], 25.2 [ranges.syn], 30.2 [time.syn], 31.12.4 [fs.filesystem.syn], 28.6.3 [re.syn], 32.4.2 [thread.syn] Status: C++20 Submitter: United States Opened: 2019-11-07 Last modified: 2021-02-25

Priority: 0

View all other issues in [coroutine.syn].

View all issues with C++20 status.

Discussion:

Addresses US 181

The spaceship operator<=> is typically not usable unless the library header <compare> is directly included by the user. Many standard library headers provide overloads for this operator. Worse, several standard classes have replaced their existing definition for comparison operators with a reliance on the spaceship operator, and existing code will break if the necessary header is not (transitively) included. In a manner similar to the mandated library headers transitively #include-ing <initializer_list> in C++11, these headers should mandate a transitive #include <compare>.

Proposed change:

Add:

#include <compare>

to the header synopsis for each of the following headers:

<array>
<chrono>
<coroutine>
<deque>
<forward_list>
<filesystem>
<iterator>
<list>
<map>
<memory>
<optional>
<queue>
<ranges>
<regex>
<set>
<stack>
<string>
<string_view>
<system_error>
<thread>
<tuple>
<type_index>
<unordered_map>
<unordered_set>
<utility>
<variant>
<vector>

[2019-11 Moved to Ready on Friday AM in Belfast]

Proposed resolution:

This wording is relative to N4835.

  1. Add

    #include <compare>
    

    to the following header synopses:

    1. 17.12.2 [coroutine.syn]
    2. 19.5.2 [system.error.syn]
    3. 22.2.1 [utility.syn]
    4. 22.4.2 [tuple.syn]
    5. 22.5.2 [optional.syn]
    6. 22.6.2 [variant.syn]
    7. 20.2.2 [memory.syn]
    8. 17.7.6 [type.index.synopsis]
    9. 27.4.2 [string.syn]
    10. 27.3.2 [string.view.synop]
    11. 23.3.2 [array.syn]
    12. 23.3.4 [deque.syn]
    13. 23.3.6 [forward.list.syn]
    14. 23.3.8 [list.syn]
    15. 23.3.10 [vector.syn]
    16. 23.4.2 [associative.map.syn]
    17. 23.4.5 [associative.set.syn]
    18. 23.5.2 [unord.map.syn]
    19. 23.5.5 [unord.set.syn]
    20. 23.6.2 [queue.syn]
    21. 23.6.5 [stack.syn]
    22. 24.2 [iterator.synopsis]
    23. 25.2 [ranges.syn]
    24. 30.2 [time.syn]
    25. 31.12.4 [fs.filesystem.syn]
    26. 28.6.3 [re.syn]
    27. 32.4.2 [thread.syn]