cplusplus / cplusplus/draft

[alg.fold] Spelling the actual`ranges::fold_meow`'s return type in function signature?

Open
#6,963 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

not-editorial
Dominant language
TeX
Stars
221
Forks
813
Avg merge
16h 4m
Merged PRs (30d)
36

Description

For people like me who have been dealing with decltype() and type traits for a long time, the return type of ranges::fold_meow is still daunting.
I had to go back and forth a few times to the various overloads to really understand what the actual return type of these overloads was, because they all were specified as auto or delctype(fold_moew(...)), which is very unintuitive, see [alg.fold] for details.
I suspect that this way of defining return types may be extremely unfriendly to non-expert users, and it would be nice if we could spell the correct concrete type directly in the function signature, for example:

template<input_iterator I, sentinel_for<I> S, class T = iter_value_t<I>,
         indirectly-binary-left-foldable<T, I> F>
constexpr decay_t<invoke_result_t<F&, iter_reference_t<I>, T>> 
ranges::fold_left(I first, S last, T init, F f);

I believe this is editorial, but not sure if there are any other implicit issue with doing this.
But what is certain is that the current way of spelling the return type is indeed inconvenient.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the [alg.fold] specification and review the current declarations and overloads that use auto or decltype(fold_meow(...)). Compare the proposed concrete return type with the existing constraints and wording, then verify that the editorial change preserves the intended semantics across all fold overloads.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.