Bug 97512 - Move std::ranges::subrange structured bindings stuff from <ranges> to <ranges_util.h>
Summary: Move std::ranges::subrange structured bindings stuff from <ranges> to <ranges...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 11.0
: P3 normal
Target Milestone: 11.0
Assignee: Jonathan Wakely
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-21 09:31 UTC by 康桓瑋
Modified: 2020-10-21 14:13 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-10-21 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description 康桓瑋 2020-10-21 09:31:11 UTC
In commit 160061a: libstdc++: Introduce new headers for C++20 ranges components, structured bindings stuff of std::ranges::subrange is move into <ranges> header itself, this will make following code failed in gcc-trunk (https://godbolt.org/z/az5bfc):

#include <vector>
#include <algorithm>

int main() {
  std::vector v{1, 1, 2};
  auto [first, last] = std::ranges::unique(v);
}


error: cannot decompose inaccessible member 'std::ranges::subrange

Put structured bindings stuff together with subrange's definition should be convenient for users, since std::ranges::remove/unique return a subrange, for a user like me usually want to structurally bind it without extra including <ranges>, or it would make sense to have these tuple-related specializations close to the get functions, which are already in the <bits/ranges_util.h> header.
Comment 1 Jonathan Wakely 2020-10-21 13:20:07 UTC
Oops, yes, I should have moved those too.
Comment 2 CVS Commits 2020-10-21 14:13:05 UTC
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:a186ab670e97c4c3883d96506655c4621e7c5515

commit r11-4188-ga186ab670e97c4c3883d96506655c4621e7c5515
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Oct 21 14:40:54 2020 +0100

    libstdc++: Make structured bindings always work for subranges [PR 97512]
    
    The definition of ranges::subrange was moved to the new
    <bits/ranges_util.h> header so that it could be used in <algorithm>
    without including the whole of <ranges>. However, the tuple-like support
    that enables subrange to be used with structured bindings was left in
    <ranges>. This is arguably conforming (to use a subrange you should
    include <ranges>) but it's inconvenient and probably confusing.
    
    This change makes the tuple-like support available whenever subrange
    itself is available.
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/97512
            * include/bits/ranges_util.h (tuple_size<subrange>)
            (tuple_element<I, cv subrange>): Move here from ...
            * include/std/ranges: ... here.
            * testsuite/std/ranges/subrange/97512.cc: New test.
Comment 3 Jonathan Wakely 2020-10-21 14:13:54 UTC
Done! Thanks for the report.