ldionne added a comment.

We should probably consider changing the name from `__nth_element` to something 
else, perhaps something that contains the word "pack". This is especially true 
if we are to implement other intrinsics for manipulating parameter packs, like 
slicing (as proposed by Eric Fiselier). Unless someone with a clearer view of 
the project suggests something, I would probably go with `__pack_element` (and 
then we could add `__pack_slice`, etc...). I have no strong preference.

This patch also raises the question of whether we should have a more separated 
way of adding builtin templates. My job here was very easy because I just 
copied David's revision and tweaked a couple of things here and there, but I 
could imagine it not being obvious at all otherwise. Also, and most 
importantly, if we add other builtin templates, do we want these builtins to 
"clutter" the rest of the code instead of being somewhat isolated? I don't know 
the answer to these questions, but I'd just like to point them out.


================
Comment at: lib/AST/DeclTemplate.cpp:1245-1249
@@ +1244,7 @@
+createNthElement(const ASTContext &C, DeclContext *DC) {
+  // typename IndexType
+  auto *IndexType = TemplateTypeParmDecl::Create(
+      C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/0,
+      /*Id=*/nullptr, /*Typename=*/true, /*ParameterPack=*/false);
+  IndexType->setImplicit(true);
+
----------------
It would be simpler and better (IMO) to have `template <std::size_t Index, 
typename ...T>` instead of `template <typename IndexType, IndexType Index, 
typename ...T>`, but I couldn't figure out how to create a non-type template 
parameter. Hence, I just adapted the code from David's revision for 
`__make_integer_seq`.

================
Comment at: lib/Sema/SemaTemplate.cpp:2101-2102
@@ +2100,4 @@
+    // We simply return the type at index `Index`.
+    // TODO:
+    // What are the implications of calling .getExtValue() on an APSInt?
+    assert(Index.getExtValue() == Index &&
----------------
More generally, what is the proper way to retrieve a non-type template argument 
as a number that I can then use as a normal `std::size_t` (or similar) in the 
code? I really just want to retrieve the index, which is given as a non-type 
template parameter to `__nth_element`, and convert it to a numeric index `n` in 
order to fetch the `n`-th element of the parameter pack.


http://reviews.llvm.org/D15421



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to