Topic: [variadic templates]n-th element of pack expansion syntax proposal


Author: Larry <cppljevans@gmail.com>
Date: Thu, 19 Nov 2009 13:58:01 CST
Raw View
As mentioned in a post of comp.std.c++:

 http://preview.tinyurl.com/yzg3dk5

there's a need for some way to get the nth element of a pack
expansion; however, the above post claims:

 This is probably the most-requested feature for variadic templates,
 and it never it made it because we never found a good, unambiguous
syntax.

Why wouldn't the syntax described by the following grammar production:

 nth-expansion-element:
   expansion-pattern '...[' constant-expression ']'

 where:
   expansion-pattern is the "pattern of the expansion" described
     on p. 327 of:

       http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n3000.pdf

   constant-expression is defined here:
     http://www.csci.csusb.edu/dick/c++std/cd2/gram.html#gram.expr

be unambiguous?  For example, boost::mpl::arg:

 http://www.boost.org/doc/libs/1_40_0/libs/mpl/doc/refmanual/arg.html

could be implemented with the following code.

 template< int n > struct arg
 {
     template< typename A...>
     struct apply
     {
         typedef A...[n] type;
     };
 };

where:

 A... is parsed as a expansion-pattern.
 n is parsed as a constant-expression.
 A...[n] is parsed as a nth-expansion-element.


Is there some document recording the various syntaxes tried and why
they were found ambiguous?

TIA.


-regards,
Larry


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]