Skip to content

Commit 8272b9e

Browse files
committed
feat(ranges): indexer
1 parent 818900b commit 8272b9e

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

include/stdsharp/cmath/cmath.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace stdsharp
1111
return (x + y - 1) / y;
1212
}
1313

14-
constexpr auto ceil_quotient(const floating_point auto x, decltype(x) y) noexcept
14+
constexpr auto ceil_quotient(const std::floating_point auto x, decltype(x) y) noexcept
1515
{
1616
return ceil(x / y);
1717
}

include/stdsharp/ranges/ranges.h

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,36 @@ namespace stdsharp
120120
return (*this)(std::ranges::cbegin(r), std::ranges::cend(r), in);
121121
}
122122
} is_iter_in{};
123+
}
123124

124-
inline constexpr struct index_fn
125+
namespace stdsharp::details
126+
{
127+
template<typename Fn>
128+
struct index_fn
125129
{
126-
template<typename R>
127-
requires std::invocable<::ranges::index_fn, R, std::ranges::range_size_t<R>>
128-
constexpr decltype(auto) operator()(R&& r, const std::ranges::range_size_t<R>& i) const
130+
template<typename R, typename... Args>
131+
constexpr decltype(auto) operator()(
132+
R&& r,
133+
const std::ranges::range_difference_t<R>& i,
134+
Args&&... args //
135+
) const
136+
requires requires(std::invoke_result_t<Fn, R, decltype(i)> result) {
137+
requires sizeof...(Args) == 0 ||
138+
std::invocable<index_fn, decltype(result), Args...>;
139+
}
129140
{
130-
return ::ranges::index(r, i);
141+
auto&& result = Fn{}(cpp_forward(r), i);
142+
if constexpr(sizeof...(Args) == 0) return result;
143+
else return (*this)(cpp_forward(result), cpp_forward(args)...);
131144
}
132-
} index{};
145+
};
146+
}
147+
148+
namespace stdsharp
149+
{
150+
inline constexpr details::index_fn<::ranges::index_fn> index{};
151+
152+
inline constexpr details::index_fn<::ranges::at_fn> index_at{};
133153
}
134154

135155
namespace stdsharp::views

0 commit comments

Comments
 (0)