llvm-project/libcxx/include/__ranges
Joe Loser 40a6be4346
[libc++] Ensure valid view for view_interface template parameter
Some types that inherit from `view_interface` do not meet the
preconditions. This came up during discussion
in https://reviews.llvm.org/D112631. Currently, the behavior is IFNDR,
but the preconditions can be easily checked, so let's do so.

In particular, we know each public member function calls the
`__derived()` private function, so we can do the check there. We
intentionally do it as a `static_assert` instead of a `requires` clause
to avoid hard erroring in some cases, such as with incomplete types. An
example hard error is:

```
llvm-project/build/include/c++/v1/__ranges/view_interface.h:48:14: note: because 'sizeof(_Tp)' would be invalid: invalid application of 'sizeof' to an incomplete type 'MoveOnlyForwardRange'
  requires { sizeof(_Tp); } &&
             ^
llvm-project/build/include/c++/v1/__ranges/view_interface.h:73:26: error: no matching member function for call to '__derived'
    return ranges::begin(__derived()) == ranges::end(__derived());
                         ^~~~~~~~~
llvm-project/libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp:187:31: note: in instantiation of function template specialization 'std::ranges::view_interface<MoveOnlyForwardRange>::empty<Mov
eOnlyForwardRange>' requested here
  assert(!std::move(moveOnly).empty());
```

Reviewed By: Quuxplusone, Mordante, #libc

Differential Revision: https://reviews.llvm.org/D112665
2021-10-29 19:04:54 -04:00
..
access.h [libc++][NFC] Fix include guard for decay_copy.h and remove underscores from the header 2021-08-27 12:45:53 -04:00
all.h [libc++][NFC] Fix include guard for decay_copy.h and remove underscores from the header 2021-08-27 12:45:53 -04:00
common_view.h [libc++] Add the std::views::common range adaptor 2021-09-29 17:27:34 -04:00
concepts.h [libc++][NFC] Remove useless _LIBCPP_PUSH_MACROS 2021-08-27 12:41:55 -04:00
copyable_box.h [libc++][NFC] Remove useless _LIBCPP_PUSH_MACROS 2021-08-27 12:41:55 -04:00
counted.h [libc++][NFC] Fix include guard for decay_copy.h and remove underscores from the header 2021-08-27 12:45:53 -04:00
dangling.h [libc++][NFC] Remove useless _LIBCPP_PUSH_MACROS 2021-08-27 12:41:55 -04:00
data.h [libc++] Remove a stray `const` on ranges::data and ranges::ssize. NFCI. 2021-09-07 13:59:21 -04:00
drop_view.h [libc++][NFC] Remove useless _LIBCPP_PUSH_MACROS 2021-08-27 12:41:55 -04:00
empty.h [libc++][NFC] Remove useless _LIBCPP_PUSH_MACROS 2021-08-27 12:41:55 -04:00
empty_view.h [libc++][NFC] Remove useless _LIBCPP_PUSH_MACROS 2021-08-27 12:41:55 -04:00
enable_borrowed_range.h [libc++][NFC] Remove useless _LIBCPP_PUSH_MACROS 2021-08-27 12:41:55 -04:00
enable_view.h [libc++][NFC] Remove useless _LIBCPP_PUSH_MACROS 2021-08-27 12:41:55 -04:00
iota_view.h [libc++] [ranges] Uncomment operator<=> in transform and iota iterators. 2021-10-02 21:26:27 -04:00
join_view.h [libc++] Do not require movability in __non_propagating_cache::__emplace_deref 2021-08-17 11:32:40 -04:00
non_propagating_cache.h [libc++] Do not require movability in __non_propagating_cache::__emplace_deref 2021-08-17 11:32:40 -04:00
range_adaptor.h [libc++] Implement the underlying mechanism for range adaptors 2021-08-26 14:07:21 -04:00
ref_view.h [libc++][NFC] Remove useless _LIBCPP_PUSH_MACROS 2021-08-27 12:41:55 -04:00
reverse_view.h [libc++] Add the std::views::reverse range adaptor 2021-10-18 10:38:31 -04:00
single_view.h [libc++][NFC] Remove useless _LIBCPP_PUSH_MACROS 2021-08-27 12:41:55 -04:00
size.h [libc++] Remove a stray `const` on ranges::data and ranges::ssize. NFCI. 2021-09-07 13:59:21 -04:00
subrange.h [libc++] Simplify std::ranges::subrange 2021-09-28 17:34:01 -04:00
take_view.h [libc++] IWYU to fix complaints when compiling with Modules. NFCI. 2021-08-05 14:30:08 -04:00
transform_view.h [libc++] [ranges] Uncomment operator<=> in transform and iota iterators. 2021-10-02 21:26:27 -04:00
view_interface.h [libc++] Ensure valid view for view_interface template parameter 2021-10-29 19:04:54 -04:00