public inbox for
 help / color / mirror / Atom feed
From: Marek Polacek <>
To: Jonathan Wakely <>
	Jason Merrill <>
Subject: Re: [PATCH] c++: Define built-in for std::tuple_element [PR100157]
Date: Thu, 7 Jul 2022 13:25:24 -0400	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

On Thu, Jul 07, 2022 at 06:14:36PM +0100, Jonathan Wakely wrote:
> This adds a new built-in to replace the recursive class template
> instantiations done by traits such as std::tuple_element and
> std::variant_alternative. The purpose is to select the Nth type from a
> list of types, e.g. __builtin_type_pack_element(1, char, int, float) is
> int.
> For a pathological example tuple_element_t<1000, tuple<2000 types...>>
> the compilation time is reduced by more than 90% and the memory  used by
> the compiler is reduced by 97%. In realistic examples the gains will be
> much smaller, but still relevant.
> Clang has a similar built-in, __type_pack_element<N, T...>, but that's a
> "magic template" built-in using <> syntax, which GCC doesn't support. So
> this provides an equivalent feature, but as a built-in function using
> parens instead of <>. I don't really like the name "type pack element"
> (it gives you an element from a pack of types) but the semi-consistency
> with Clang seems like a reasonable argument in favour of keeping the
> name. I'd be open to alternative names though, e.g. __builtin_nth_type
> or __builtin_type_at_index.
> The patch has some problems though ...
> FIXME 1: Marek pointed out that this this ICEs:
> template<class... T> using type = __builtin_type_pack_element(sizeof(T), T...);
> type<int, char> c;
> The sizeof(T) expression is invalid, because T is an unexpanded pack,
> but it's not rejected and instead crashes:

I think this could be fixed by

  if (check_for_bare_parameter_packs (n))
    return error_mark_node;

in finish_type_pack_element.

(I haven't looked at the rest of the patch yet.)


  reply	other threads:[~2022-07-07 17:25 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-07 17:14 Jonathan Wakely
2022-07-07 17:25 ` Marek Polacek [this message]
2022-07-07 19:28 ` Jason Merrill
2022-07-07 20:46   ` Jonathan Wakely
2022-10-05 13:43 ` Patrick Palka
2023-01-09 15:53   ` Patrick Palka
2023-01-09 19:25     ` Patrick Palka
2023-01-10 10:17       ` Jonathan Wakely
2023-01-17 18:04       ` Jason Merrill
2023-01-25 20:35         ` Patrick Palka
2023-01-26 17:47           ` Jason Merrill
2023-04-11 14:21             ` Patrick Palka
2023-04-18 19:09               ` Jason Merrill
2023-04-18 19:23                 ` Patrick Palka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).