From c5452ed941909c04dcae6466677b4dffcf88e09e Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 19 Oct 2016 22:18:42 +0000 Subject: Add optimization to sizeof...(X) handling: if none of parameter pack X's corresponding arguments are unexpanded pack expansions, we can compute the result without substituting them. This significantly improves the memory usage and performance of make_integer_sequence implementations that do this kind of thing: using result = integer_sequence; ... but note that such an implementation will still perform O(sizeof...(Ns)^2) work while building the second pack expansion (we just have a somewhat lower constant now). In principle we could get this down to linear time by caching whether the number of expansions of a pack is constant, or checking whether we're within an alias template before scanning the pack for pack expansions (since that's the only case in which we do substitutions within a dependent context at the moment), but this patch doesn't attempt that. llvm-svn: 284653 --- clang/include/clang/Sema/Sema.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'clang/include') diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 78080f5e4a4..78be700ec3a 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -6499,6 +6499,14 @@ public: SourceLocation &Ellipsis, Optional &NumExpansions) const; + /// Given a template argument that contains an unexpanded parameter pack, but + /// which has already been substituted, attempt to determine the number of + /// elements that will be produced once this argument is fully-expanded. + /// + /// This is intended for use when transforming 'sizeof...(Arg)' in order to + /// avoid actually expanding the pack where possible. + Optional getFullyPackExpandedSize(TemplateArgument Arg); + //===--------------------------------------------------------------------===// // C++ Template Argument Deduction (C++ [temp.deduct]) //===--------------------------------------------------------------------===// -- cgit v1.2.3