Topic: pattern expansion with non-pack present
Author: Pavel Minaev <int19h@gmail.com>
Date: Tue, 5 May 2009 14:09:51 CST Raw View
On May 4, 9:52 pm, cppljev...@gmail.com wrote:
> template<class T, T... C>
> struct SEQ_c
> : SEQ<integral_c<T,C>...>
> {};
>
> ? I tried compiling something like this; however, I got
> a compile error:
>
> error: parameter packs not expanded with '...':
Shouldn't it actually be "integral_c<T, C...>" (i.e. expand the C,
since it's a pack)?
--
[ 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 ]
Author: cppljevans@gmail.com
Date: Tue, 5 May 2009 14:33:50 CST Raw View
On May 5, 3:09 pm, Pavel Minaev <int...@gmail.com> wrote:
> On May 4, 9:52 pm, cppljev...@gmail.com wrote:
>
> > template<class T, T... C>
> > struct SEQ_c
> > : SEQ<integral_c<T,C>...>
> > {};
>
> > ? I tried compiling something like this; however, I got
> > a compile error:
>
> > error: parameter packs not expanded with '...':
>
> Shouldn't it actually be "integral_c<T, C...>" (i.e. expand the C,
> since it's a pack)?
The integral-sequence-wrapper.html is supposed to convey the
idea that SEQ_C is composed of a sequence composed of:elements:
integral_c<T,c1>
integral_c<T,c2>
...
integral_c<T,cN>
So, no I didn't mean for the expansion to be integral_c<T,C...>.
I was hoping that, since T was not a package, the compiler
would treat it like some constant type, e.g. int, instead of
like a template parameter. The list_c_expansion_wish.cpp
was supposed to make it clearer, but I guess I need to
work a little more on my communication skills.
Sorry for the confusion.
-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 ]
Author: cppljevans@gmail.com
Date: Wed, 6 May 2009 10:39:40 CST Raw View
On May 5, 3:33 pm, cppljev...@gmail.com wrote:
> On May 5, 3:09 pm, Pavel Minaev <int...@gmail.com> wrote:
>
> > On May 4, 9:52 pm, cppljev...@gmail.com wrote:
>
> > > template<class T, T... C>
> > > struct SEQ_c
> > > : SEQ<integral_c<T,C>...>
> > > {};
[snip]
> > Shouldn't it actually be "integral_c<T, C...>" (i.e. expand the C,
> > since it's a pack)?
[snip]
Probably what you're really missing is the concept of "unpacking
patterns"
as described in section 2.4 of:
http://www.generic-programming.org/~dgregor/cpp/variadic-templates.pdf
There a pattern, AFAICT, can be some expression, E, which contains
a "pack name". For example, the section 2.4 contains:
Args&...
The pack name is Args but the expression is Args&. In the integral_c
case, the pack name is C but the expression is integral_c<T,C>.
Maybe "pack name" is the wrong term, but hopefully that makes
things clearer.
--
[ 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 ]
Author: cppljevans@gmail.com
Date: Thu, 7 May 2009 12:17:03 CST Raw View
On 05/06/09 11:39, cppljevans@gmail.com wrote:
[snip]
>
> Probably what you're really missing is the concept of "unpacking
> patterns"
> as described in section 2.4 of:
>
> http://www.generic-programming.org/~dgregor/cpp/variadic-templates.pdf
>
> There a pattern, AFAICT, can be some expression, E, which contains
> a "pack name". For example, the section 2.4 contains:
>
> Args&...
>
> The pack name is Args but the expression is Args&. In the integral_c
> case, the pack name is C but the expression is integral_c<T,C>.
>
> Maybe "pack name" is the wrong term, but hopefully that makes
> things clearer.
A better reference is:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2242.pdf
where, in section 3.6.1 there terms:
parameter pack
pack expansion
pattern of pack expansion (or pack expansion pattern)
In the list_c_expansion_wish.cpp code mentioned in my previous post,
`Args` is a parameter pack.
`integral_c<Integral,Args>...` is a pack expansion.
`integral_c<Integral,Args>` is the pattern of the above pack
expansion.
The section 3.6.1 suggested that the code should work; hence, I
simplified it to isolate the reason for its failure. The code below
compiles OK; hence, there must be something wrong with the original
code. I'm still investigating why.
//-{--demo of gcc4.4 compiler w.r.t. parameter pack expansions--
enum
A
{ a0
, a1
, a2
, a3
};
template
< typename Integral
, Integral Value
>
struct integral_c
{};
template
< typename... Types
>
struct seq
{};
template
< typename Integral
, Integral... Values
>
struct seq_c
: seq
< integral_c
< Integral
, Values //template param pack.
>// pattern of pattern expansion.
...//the pattern expansion
>
{
};
typedef
seq_c
< A
, a0
, a1
, a2
>
actual_seq_cA3
;
//-}--demo of gcc4.4 compiler w.r.t. parameter pack expansions--
--
[ 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 ]