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

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], 22.11.1 [type.index.synopsis], 23.4.2 [string.syn], 23.3.2 [string.view.synop], 24.3.2 [array.syn], 24.3.3 [deque.syn], 24.3.4 [forward.list.syn], 24.3.5 [list.syn], 24.3.6 [vector.syn], 24.4.2 [associative.map.syn], 24.4.3 [associative.set.syn], 24.5.2 [unord.map.syn], 24.5.3 [unord.set.syn], 24.6.2 [queue.syn], 24.6.3 [stack.syn], 25.2 [iterator.synopsis], 26.2 [ranges.syn], 29.2 [time.syn], 31.12.4 [fs.filesystem.syn], 32.3 [re.syn], 33.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. 22.11.1 [type.index.synopsis]
    9. 23.4.2 [string.syn]
    10. 23.3.2 [string.view.synop]
    11. 24.3.2 [array.syn]
    12. 24.3.3 [deque.syn]
    13. 24.3.4 [forward.list.syn]
    14. 24.3.5 [list.syn]
    15. 24.3.6 [vector.syn]
    16. 24.4.2 [associative.map.syn]
    17. 24.4.3 [associative.set.syn]
    18. 24.5.2 [unord.map.syn]
    19. 24.5.3 [unord.set.syn]
    20. 24.6.2 [queue.syn]
    21. 24.6.3 [stack.syn]
    22. 25.2 [iterator.synopsis]
    23. 26.2 [ranges.syn]
    24. 29.2 [time.syn]
    25. 31.12.4 [fs.filesystem.syn]
    26. 32.3 [re.syn]
    27. 33.4.2 [thread.syn]