Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix & Update <ranges> #18

Merged
merged 54 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
12466ae
Fix
lackhole Jun 22, 2024
553977e
Update ranges.cc
lackhole Jun 22, 2024
46e8281
Update README.md
lackhole Jun 22, 2024
b7665d4
Update subrange.h
lackhole Jun 22, 2024
6c5839b
Update subrange.h
lackhole Jun 22, 2024
6b90fe1
Fic for gcc
lackhole Jun 22, 2024
eb2c162
Update cxx20_rel_ops.h
lackhole Jun 22, 2024
0c0196e
Update README.md
lackhole Jun 22, 2024
c79d39e
Update cxx20_rel_ops.h
lackhole Jun 22, 2024
6819896
Update cxx20_rel_ops.h
lackhole Jun 22, 2024
e4752d4
Update apply.h
lackhole Jun 22, 2024
7f09498
Add tuple_integer_sequence
lackhole Jun 22, 2024
b4e714f
Update tuple_transform.h
lackhole Jun 22, 2024
e484a10
Update tuple_for_each.h
lackhole Jun 22, 2024
bbbc558
Update sequence_for_each.h
lackhole Jun 22, 2024
1ed3ef6
Update cartesian_product_view.h
lackhole Jun 22, 2024
efa2d5c
Update ranges_views.cc
lackhole Jun 22, 2024
f7d5fb4
Update ranges_views.cc
lackhole Jun 22, 2024
05962f7
Update cxx20_rel_ops.h
lackhole Jun 22, 2024
ceffab0
Update cxx20_rel_ops.h
lackhole Jun 22, 2024
45e3c3e
Update ranges.cc
lackhole Jun 22, 2024
ecfe1c4
Update ranges_views.cc
lackhole Jun 22, 2024
d3f86cf
Update range_adaptor_closure.h
lackhole Jun 23, 2024
793d9c3
Add test for ref_view
lackhole Jun 23, 2024
87ba6cf
Update contiguous_iterator.h
lackhole Jun 23, 2024
ca1c651
Add test for owning_view
lackhole Jun 23, 2024
d09ab4a
Fix filter_view
lackhole Jun 23, 2024
a150a0d
Update ranges_views.cc
lackhole Jun 23, 2024
5b8688f
Update owning_view.h
lackhole Jun 23, 2024
cc16727
Update transform_view to match C++23 spec
lackhole Jun 23, 2024
dee28ef
Fix range niebloids uses wrong CTAD
lackhole Jun 23, 2024
8b26a26
Update ranges_views.cc
lackhole Jun 23, 2024
e67bf97
Update ranges_views.cc
lackhole Jun 23, 2024
ebaf8f8
Update ranges_views.cc
lackhole Jun 23, 2024
4010c47
Fix bind_xxx decaying arguments
lackhole Jun 23, 2024
a7cd16c
Fix take_view
lackhole Jun 23, 2024
6aea1bb
Fix wraning
lackhole Jun 28, 2024
4cdb25e
Fix take_while_view
lackhole Jun 28, 2024
a2dccfb
Update ranges_views.cc
lackhole Jun 28, 2024
99a2768
Update ranges_views.cc
lackhole Jun 28, 2024
4833457
Move to_unsigned_like
lackhole Jun 28, 2024
68b16ba
Fix drop/drop_view
lackhole Jun 28, 2024
23491bd
Update ranges_views.cc
lackhole Jun 28, 2024
aff7f4f
Update ranges_views.cc
lackhole Jun 28, 2024
657cea1
Add has_conversion_operator
lackhole Jun 28, 2024
bfe8320
Fix drop_while_view
lackhole Jun 28, 2024
27718fa
Update ranges_views.cc
lackhole Jun 28, 2024
82e5606
Fix join_view
lackhole Jun 30, 2024
0e54690
Update ranges_views.cc
lackhole Jun 30, 2024
3814b99
Update README.md
lackhole Jun 30, 2024
7d2b5ed
Refactor split_view
lackhole Jun 30, 2024
ad480e8
Refactor views::split
lackhole Jun 30, 2024
0d95d0d
Add test for split_view
lackhole Jun 30, 2024
a88a4bc
Update ranges_views.cc
lackhole Jun 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 39 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,37 +358,38 @@ Description

* `<concepts>`

| | Introduced | Revision |
|-------------------------|------------|----------|
| `same_as` | ![][c20ok] | |
| `derived_from` | ![][c20ok] | |
| `convertible_to` | ![][c20ok] | |
| `common_reference_with` | ![][c20ok] | |
| `common_with` | ![][c20ok] | |
| `integral` | ![][c20ok] | |
| `signed_integral` | ![][c20ok] | |
| `unsigned_integral` | ![][c20ok] | |
| `floating_point` | ![][c20ok] | |
| `assignable_from` | ![][c20ok] | |
| `swappable` | ![][c20ok] | |
| `destructible` | ![][c20ok] | |
| `constructible_from` | ![][c20ok] | |
| `default_initializable` | ![][c20ok] | |
| `move_constructible` | ![][c20ok] | |
| `copy_constructible` | ![][c20ok] | |
| `equality_comparable` | ![][c20ok] | |
| `totally_ordered` | ![][c20ok] | |
| `movable` | ![][c20ok] | |
| `copyable` | ![][c20ok] | |
| `semiregular` | ![][c20ok] | |
| `regular` | ![][c20ok] | |
| `invocable` | ![][c20ok] | |
| `regular_invocable` | ![][c20ok] | |
| `predicate` | ![][c20ok] | |
| `relation` | ![][c20ok] | |
| `equivalence_relation` | ![][c20ok] | |
| `strict_weak_order` | ![][c20ok] | |
| `ranges::swap` | ![][c20ok] | |
| | Introduced | Revision |
|----------------------------|------------|------------|
| `same_as` | ![][c20ok] | |
| `derived_from` | ![][c20ok] | |
| `convertible_to` | ![][c20ok] | |
| `common_reference_with` | ![][c20ok] | |
| `common_with` | ![][c20ok] | |
| `integral` | ![][c20ok] | |
| `signed_integral` | ![][c20ok] | |
| `unsigned_integral` | ![][c20ok] | |
| `floating_point` | ![][c20ok] | |
| `assignable_from` | ![][c20ok] | |
| `swappable` | ![][c20ok] | |
| `destructible` | ![][c20ok] | |
| `constructible_from` | ![][c20ok] | |
| `default_initializable` | ![][c20ok] | |
| `move_constructible` | ![][c20ok] | |
| `copy_constructible` | ![][c20ok] | |
| `equality_comparable` | ![][c20ok] | |
| `equality_comparable_with` | ![][c20ok] | ![][c23ok] |
| `totally_ordered` | ![][c20ok] | |
| `movable` | ![][c20ok] | |
| `copyable` | ![][c20ok] | |
| `semiregular` | ![][c20ok] | |
| `regular` | ![][c20ok] | |
| `invocable` | ![][c20ok] | |
| `regular_invocable` | ![][c20ok] | |
| `predicate` | ![][c20ok] | |
| `relation` | ![][c20ok] | |
| `equivalence_relation` | ![][c20ok] | |
| `strict_weak_order` | ![][c20ok] | |
| `ranges::swap` | ![][c20ok] | |

* `<coroutine>` N/A

Expand Down Expand Up @@ -660,7 +661,7 @@ Description
| `ranges::contiguous_range` | ![][c20ok] | |
| `ranges::common_range` | ![][c20ok] | |
| `ranges::viewable_range` | ![][c20ok] | |
| `ranges::constant_range` | ![][c20ok] | |
| `ranges::constant_range` | ![][c23ok] | |
| `ranges::to` | ![][c23ok] (Partial) | |
| `ranges::iterator_t` | ![][c20ok] | |
| `ranges::const_iterator_t` | ![][c23ok] | |
Expand All @@ -670,11 +671,11 @@ Description
| `ranges::range_size_t` | ![][c20ok] | |
| `ranges::range_value_t` | ![][c20ok] | |
| `ranges::range_refernce_t` | ![][c20ok] | |
| `ranges::range_const_reference_t` | ![][c20ok] | |
| `ranges::range_const_reference_t` | ![][c23ok] | |
| `ranges::range_rvalue_reference_t` | ![][c20ok] | |
| `ranges::range_common_reference_t` | ![][c20ok] | |
| `ranges::view_interface` | ![][c20ok] | |
| `ranges::subrange` | ![][c20ok] | |
| `ranges::view_interface` | ![][c20ok] | ![][c23ok] |
| `ranges::subrange` | ![][c20ok] | ![][c23ok] |
| `ranges::dangling` | ![][c20ok] | |
| `ranges::borrowed_iterator_t` | ![][c20ok] | |
| `ranges::borrowed_subrange_t` | ![][c20ok] | |
Expand All @@ -690,13 +691,13 @@ Description
| `ranges::ref_view` | ![][c20ok] | |
| `ranges::owning_view` | ![][c20ok] | |
| `ranges::filter_view`<br/>`views::filter` | ![][c20ok] | |
| `ranges::transform_view`<br/>`views::transform` | ![][c20ok] | |
| `ranges::transform_view`<br/>`views::transform` | ![][c20ok] | ![][c23ok] |
| `ranges::take_view`<br/>`views::take` | ![][c20ok] | |
| `ranges::take_while_view`<br/>`views::take_while` | ![][c20ok] | |
| `ranges::drop_view`<br/>`views::drop` | ![][c20ok] | |
| `ranges::drop_view`<br/>`views::drop` | ![][c20ok] | ![][c23ok] |
| `ranges::drop_while_view`<br/>`views::drop_while` | ![][c20ok] | |
| `ranges::join_view`<br/>`views::join` | ![][c20ok] | |
| `ranges::lazy_split_view`<br/>`views::lazy_split` | ![][c20ok] | |
| `ranges::lazy_split_view`<br/>`views::lazy_split` | ![][c20no] | |
| `ranges::split_view`<br/>`views::split` | ![][c20ok] | |
| `views::counted` | ![][c20ok] | |
| `ranges::common_view`<br/>`views::common` | ![][c20ok] | |
Expand Down
2 changes: 1 addition & 1 deletion include/preview/__functional/bind_back.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ template<typename F, typename... Args, std::enable_if_t<conjunction<
std::is_move_constructible<std::decay_t<Args>>...
>::value, int> = 0>
constexpr auto bind_back(F&& f, Args&&... args) {
return detail::bind_back_object<std::decay_t<F>, std::decay_t<Args>...>{
return detail::bind_back_object<std::decay_t<F>, Args&&...>{
detail::bind_object_ctor_tag{},
std::forward<F>(f),
std::forward<Args>(args)...
Expand Down
2 changes: 1 addition & 1 deletion include/preview/__functional/bind_front.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ template<typename F, typename... Args, std::enable_if_t<conjunction<
std::is_move_constructible<std::decay_t<Args>>...
>::value, int> = 0>
constexpr auto bind_front(F&& f, Args&&... args) {
return detail::bind_front_object<std::decay_t<F>, std::decay_t<Args>...>{
return detail::bind_front_object<std::decay_t<F>, Args&&...>{
detail::bind_object_ctor_tag{},
std::forward<F>(f),
std::forward<Args>(args)...
Expand Down
1 change: 0 additions & 1 deletion include/preview/__functional/detail/bind_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class bind_object_base {
constexpr typename bind_invoke_result<Derived&, U&&...>::type
operator()(U&&... args) & noexcept(bind_nothrow_invocable<Derived&, U&&...>::value) {
return call(*this, std::forward<U>(args)...);
return Derived::call(derived(), index_sequence{}, std::forward<U>(args)...);
}

template<typename... U>
Expand Down
5 changes: 3 additions & 2 deletions include/preview/__iterator/contiguous_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "preview/__concepts/derived_from.h"
#include "preview/__concepts/same_as.h"
#include "preview/__concepts/requires_expression.h"
#include "preview/__iterator/detail/have_cxx20_iterator.h"
#include "preview/__iterator/detail/iter_concept.h"
#include "preview/__iterator/iterator_traits/legacy_random_access_iterator.h"
#include "preview/__iterator/iter_reference_t.h"
Expand Down Expand Up @@ -48,11 +49,11 @@ struct contiguous_iterator_impl : std::false_type {};
template<typename I>
struct contiguous_iterator_impl<I, true>
: conjunction<
#if __cplusplus < 202002L
#if !PREVIEW_STD_HAVE_CXX20_ITERATOR
disjunction<
#endif
derived_from<ITER_CONCEPT<I>, contiguous_iterator_tag>,
#if __cplusplus < 202002L
#if !PREVIEW_STD_HAVE_CXX20_ITERATOR
conjunction<
derived_from<ITER_CONCEPT<I>, random_access_iterator_tag>,
LegacyRandomAccessIterator<I>
Expand Down
7 changes: 0 additions & 7 deletions include/preview/__ranges/owning_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,6 @@ class owning_view : public view_interface<owning_view<R>> {
R r_;
};

#if __cplusplus >= 201703L

template<typename R>
owning_view(R&&) -> owning_view<R>;

#endif

} // namespace ranges
} // namespace namespace preview

Expand Down
14 changes: 13 additions & 1 deletion include/preview/__ranges/range_adaptor_closure.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ struct basic_range {
unsigned char data_;
};

struct ubiq_range {
ubiq_range() = default;

template<typename T, std::enable_if_t<range<remove_cvref_t<T>>::value, int> = 0>
operator T() const noexcept;
};

template<typename C, typename D>
class range_adaptor_closure_object
: protected compressed_pair<C, D>
Expand Down Expand Up @@ -75,7 +82,10 @@ template<typename T>
struct is_range_adaptor_closure
: conjunction<
derived_from_single_crtp<T, range_adaptor_closure>,
is_invocable<T, detail::basic_range>,
disjunction<
is_invocable<T, detail::basic_range>,
is_invocable<T, detail::ubiq_range>
>,
negation< range<T> >
> {};

Expand All @@ -84,6 +94,8 @@ struct range_adaptor_closure {
static_assert(std::is_object<Derived>::value, "Constraints not satisfied");
static_assert(same_as<Derived, std::remove_cv_t<Derived>>::value, "Constraints not satisfied");

using _$preview_derived = Derived;

template<typename Range, typename This, std::enable_if_t<conjunction<
same_as<Derived, remove_cvref_t<This>>,
range<remove_cvref_t<Range>>
Expand Down
93 changes: 38 additions & 55 deletions include/preview/__ranges/subrange.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,42 +70,19 @@ struct make_unsigned_like<T, true> {
template<typename T>
using make_unsigned_like_t = typename make_unsigned_like<T>::type;

template<typename T, typename U, typename V, bool = pair_like<T>::value /* true */>
template<typename T, typename U, typename V, bool = pair_like<T>::value /* false */>
struct pair_like_convertible_from
: conjunction<
negation< range<T> >,
negation< std::is_reference<T> >,
constructible_from<T, U, V>,
convertible_to_non_slicing<U, std::tuple_element_t<0, T>>,
convertible_to<V, std::tuple_element_t<1, T>>
> {};
: std::false_type {};

template<typename T, typename U, typename V>
struct pair_like_convertible_from<T, U, V, false> : std::false_type {};

template<typename R, bool = borrowed_range<R>::value /* true */>
struct borrowed_range_difference {
using type = range_difference_t<R>;
};
template<typename R>
struct borrowed_range_difference<R, false> {};
template<typename R>
using borrowed_range_difference_t = typename borrowed_range_difference<R>::type;

template<
typename I,
typename S = I,
subrange_kind K = sized_sentinel_for<S, I>::value ? subrange_kind::sized : subrange_kind::unsized
>
struct is_subrange_constructible
struct pair_like_convertible_from<T, U, V, true>
: conjunction<
input_or_output_iterator<I>,
sentinel_for<S, I>,
disjunction<
bool_constant<(K == subrange_kind::sized)>,
negation< sized_sentinel_for<S, I> >
>
> {};
negation< range<T> >,
negation< std::is_reference<T> >,
constructible_from<T, U, V>,
convertible_to_non_slicing<U, std::tuple_element_t<0, T>>,
convertible_to<V, std::tuple_element_t<1, T>>
> {};

template<typename I, typename S, bool Store /* false */>
struct subrange_size {
Expand All @@ -123,18 +100,7 @@ struct subrange_size<I, S, true> {
std::make_unsigned_t<iter_difference_t<I>> size_ = 0;
};

template<typename I, typename S, typename R, bool = borrowed_range<R>::value /* true */>
struct subrange_ctor_range
: conjunction<
convertible_to_non_slicing<iterator_t<R>, I>,
convertible_to<sentinel_t<R>, S>
> {};

template<typename I, typename S, typename R>
struct subrange_ctor_range<I, S, R, false> : std::false_type {};


}
} // namespace detail

template<
typename I,
Expand Down Expand Up @@ -170,7 +136,9 @@ class subrange

template<typename R, std::enable_if_t<conjunction<
different_from<subrange, R>,
detail::subrange_ctor_range<I, S, R>,
borrowed_range<R>,
detail::convertible_to_non_slicing<iterator_t<R>, I>,
convertible_to<sentinel_t<R>, S>,
disjunction<
negation<store_size>,
sized_range<R>
Expand All @@ -180,7 +148,9 @@ class subrange
: subrange(r, static_cast<detail::make_unsigned_like_t<iter_difference_t<I>>>(ranges::size(r))) {}

template<typename R, std::enable_if_t<conjunction<
detail::subrange_ctor_range<I, S, R>,
borrowed_range<R>,
detail::convertible_to_non_slicing<iterator_t<R>, I>,
convertible_to<sentinel_t<R>, S>,
bool_constant< K == subrange_kind::sized >
>::value, int> = 0>
constexpr subrange(R&& r, detail::make_unsigned_like_t<iter_difference_t<I>> n)
Expand Down Expand Up @@ -297,16 +267,29 @@ make_subrange(R&& r, detail::make_unsigned_like_t<range_difference_t<R>> n) {
}


#if __cplusplus >= 201703L

// template<typename R>
// subrange(R&&, detail::make_unsigned_like_t<range_difference_t<R>>) ->
// subrange<ranges::iterator_t<R>, ranges::sentinel_t<R>, ranges::subrange_kind::sized>;
//
// template<typename I, typename S> subrange(I, S) -> subrange<I, S>;
//
// ^^^^^^^^^^ These two are ambiguous without constraints
#if PREVIEW_CXX_VERSION >= 17
// These two are ambiguous without constraints
// vvvvvvvvvvvvvvvvvvvv
template<typename R>
subrange(R&&, detail::make_unsigned_like_t<range_difference_t<R>>) ->
subrange<
std::enable_if_t<borrowed_range<R>::value,
ranges::iterator_t<R>>,
ranges::sentinel_t<R>,
ranges::subrange_kind::sized
>;

template<typename I, typename S>
subrange(I, S)
-> subrange<
std::enable_if_t<conjunction<
input_or_output_iterator<I>,
sentinel_for<S, I>
>::value,
I>,
S
>;
// ^^^^^^^^^^^^^^^^^^^^

template<typename I, typename S>
subrange(I, S, detail::make_unsigned_like_t<iter_difference_t<I>>) ->
Expand Down
23 changes: 11 additions & 12 deletions include/preview/__ranges/views/all.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "preview/__ranges/ref_view.h"
#include "preview/__ranges/view.h"
#include "preview/__ranges/viewable_range.h"
#include "preview/__type_traits/conditional.h"
#include "preview/__type_traits/detail/return_category.h"
#include "preview/__type_traits/conjunction.h"

Expand All @@ -28,17 +29,17 @@ using preview::detail::return_category;
class all_adaptor_closure : public range_adaptor_closure<all_adaptor_closure> {
template<typename T>
using return_category_type =
std::conditional_t<
view<std::decay_t<T>>::value, return_category<1, std::decay_t<T>>,
std::conditional_t<
conjunction<
conditional_t<
view<std::decay_t<T>>, return_category<1, std::decay_t<T>>,
conjunction< // ref_view{T}
std::is_lvalue_reference<T>,
std::is_convertible<T, std::add_lvalue_reference_t<std::remove_reference_t<T>>>,
range<std::remove_reference_t<T>>,
std::is_object<std::remove_reference_t<T>>,
std::is_lvalue_reference<T>
>::value,
return_category<2, ref_view<std::remove_reference_t<T>>>,
return_category<3, owning_view<std::remove_reference_t<T>>>
>>;
std::is_object<std::remove_reference_t<T>>
>,
return_category<2, ref_view<std::remove_reference_t<T>>>,
return_category<3, owning_view<std::remove_reference_t<T>>>
>;

template<typename R, typename T>
constexpr T operator()(R&& r, return_category<1, T>) const {
Expand All @@ -56,8 +57,6 @@ class all_adaptor_closure : public range_adaptor_closure<all_adaptor_closure> {
}

public:
all_adaptor_closure() = default;

template<typename R>
constexpr typename return_category_type<R&&>::return_type
operator()(R&& r) const {
Expand Down
Loading