Skip to content

Improve P1789 description - #108

Merged
cdervis merged 2 commits into
cdervis:mainfrom
Tsche:patch-1
Mar 10, 2026
Merged

Improve P1789 description#108
cdervis merged 2 commits into
cdervis:mainfrom
Tsche:patch-1

Conversation

@Tsche

@Tsche Tsche commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

The previous description did not capture the intended use for this feature properly. There is not much point in introducing an index sequence to operate on a single pack/tuple-like - it's more interesting for operating on more than one of those things at the same time.

I've changed the example to a simple tuple comparison - this should showcase how this change can improve pre-C++26 code.

Additionally a few little nitpicks in the "What it does" section:

  • we don't specialize get, we provide ADL-discoverable overloads
  • the point of introducing packs via structured binding is to stay within the same function scope (this matters because of P3096, see paper)

Signed-off-by: Matthias Wippich <mfwippich@gmail.com>
@Tsche

Tsche commented Mar 9, 2026

Copy link
Copy Markdown
Contributor Author

To be fair, there are uses for this with a single pack/tuple-like. For example, consider a HOF that reverses the argument list:

#include <functional>
#include <utility>

template<class F, class... Args>
decltype(auto) reverse_parameter_pack(F&& fnc, Args&&... args) {
  static constexpr auto [...Idx] = std::index_sequence_for<Args...>();
  return std::invoke(std::forward<F>(fnc), 
      std::forward<Args...[sizeof...(args)-Idx-1]>(args...[sizeof...(args)-Idx-1])...);
}

Comment thread content/expansion-statements-library-support.md
Comment thread content/expansion-statements-library-support.md
}
assert(not is_eq_iile(tup, tup2));
assert(not is_eq_fold(tup, tup2));
assert(not is_eq_template_for(tup, tup2));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use ! instead of not, just to be consistent with other example codes across our data files.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like that makes it a lot less readable, but sure :P

@cdervis

cdervis commented Mar 9, 2026

Copy link
Copy Markdown
Owner

Hi @Tsche , thanks for your contribution. I agree with your points, and besides some nitpicks we can definitely integrate this. Could you please make the adjustments I commented?

Signed-off-by: Matthias Wippich <mfwippich@gmail.com>
@cdervis

cdervis commented Mar 10, 2026

Copy link
Copy Markdown
Owner

To be fair, there are uses for this with a single pack/tuple-like. For example, consider a HOF that reverses the argument list:

#include <functional>
#include <utility>

template<class F, class... Args>
decltype(auto) reverse_parameter_pack(F&& fnc, Args&&... args) {
  static constexpr auto [...Idx] = std::index_sequence_for<Args...>();
  return std::invoke(std::forward<F>(fnc), 
      std::forward<Args...[sizeof...(args)-Idx-1]>(args...[sizeof...(args)-Idx-1])...);
}

I think your current changes are fine as-is. They get the point across well.

@cdervis
cdervis merged commit a87de8d into cdervis:main Mar 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants