diff options
author | Eric Fiselier <eric@efcs.ca> | 2016-07-01 01:24:09 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2016-07-01 01:24:09 +0000 |
commit | 6ad68551c3fbf780f91a3351e0704a7707fc19cf (patch) | |
tree | 58b84fc68050bbe39359d3effbe119c302b6f40e /clang/lib/AST/DeclTemplate.cpp | |
parent | 762c5ca3ee1441b4d2e5554846be614d871e2eca (diff) | |
download | bcm5719-llvm-6ad68551c3fbf780f91a3351e0704a7707fc19cf.tar.gz bcm5719-llvm-6ad68551c3fbf780f91a3351e0704a7707fc19cf.zip |
[Feature] Add a builtin for indexing into parameter packs. Patch by Louis Dionne.
This patch adds a __nth_element builtin that allows fetching the n-th type of a
parameter pack with very little compile-time overhead. The patch was inspired by
r252036 and r252115 by David Majnemer, which add a similar __make_integer_seq
builtin for efficiently creating a std::integer_sequence.
Reviewed as D15421. http://reviews.llvm.org/D15421
llvm-svn: 274316
Diffstat (limited to 'clang/lib/AST/DeclTemplate.cpp')
-rw-r--r-- | clang/lib/AST/DeclTemplate.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp index de3ebd23ef4..65bb2692de0 100644 --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -1239,11 +1239,34 @@ createMakeIntegerSeqParameterList(const ASTContext &C, DeclContext *DC) { Params, SourceLocation()); } +static TemplateParameterList * +createTypePackElementParameterList(const ASTContext &C, DeclContext *DC) { + // std::size_t Index + TypeSourceInfo *TInfo = C.getTrivialTypeSourceInfo(C.getSizeType()); + auto *Index = NonTypeTemplateParmDecl::Create( + C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/0, + /*Id=*/nullptr, TInfo->getType(), /*ParameterPack=*/false, TInfo); + + // typename ...T + auto *Ts = TemplateTypeParmDecl::Create( + C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/1, + /*Id=*/nullptr, /*Typename=*/true, /*ParameterPack=*/true); + Ts->setImplicit(true); + + // template <std::size_t Index, typename ...T> + NamedDecl *Params[] = {Index, Ts}; + return TemplateParameterList::Create(C, SourceLocation(), SourceLocation(), + llvm::makeArrayRef(Params), + SourceLocation()); +} + static TemplateParameterList *createBuiltinTemplateParameterList( const ASTContext &C, DeclContext *DC, BuiltinTemplateKind BTK) { switch (BTK) { case BTK__make_integer_seq: return createMakeIntegerSeqParameterList(C, DC); + case BTK__type_pack_element: + return createTypePackElementParameterList(C, DC); } llvm_unreachable("unhandled BuiltinTemplateKind!"); |