According to the MPL reference, a placeholder expression
X
on Fri Jul 27 2007, "JOAQUIN LOPEZ MU?Z"
According to the MPL reference, a placeholder expression X
must satisfy (among others) the following condition: "All of X's template parameters, including the default ones, are types."
According to that the following should then compile without errors:
#include
#include #include using namespace boost; using namespace boost::mpl;
template
struct foo { template<typename Q> struct apply{ typedef Q type; }; }; typedef apply1
,int>::type t1; BOOST_MPL_ASSERT((is_same
)); int main(){}
I don't see how you can conclude the above will compile without error just from (a part of) the definition of placeholder expression. Are you saying that since foo<_1> is not a placeholder expression, when applied to int it should be treated as a metafunction class? -- Dave Abrahams Boost Consulting http://www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com
David Abrahams
on Fri Jul 27 2007, "JOAQUIN LOPEZ MU?Z"
wrote: According to the MPL reference, a placeholder expression X
must satisfy (among others) the following condition: "All of X's template parameters, including the default ones, are types."
According to that the following should then compile without errors: [...] I don't see how you can conclude the above will compile without error just from (a part of) the definition of placeholder expression.
Are you saying that since foo<_1> is not a placeholder expression, when applied to int it should be treated as a metafunction class?
Yes, this is exactly my point. Another way in which foo<_1>
can be forced to not be treated as a ph expression is this:
// no of parms > BOOST_MPL_LIMIT_METAFUNCTION_ARITY
template
On 7/28/07, Joaquin M Lopez Munoz
David Abrahams
writes: on Fri Jul 27 2007, "JOAQUIN LOPEZ MU?Z"
wrote: According to the MPL reference, a placeholder expression X
must satisfy (among others) the following condition: "All of X's template parameters, including the default ones, are types."
According to that the following should then compile without errors: [...] I don't see how you can conclude the above will compile without error just from (a part of) the definition of placeholder expression.
Are you saying that since foo<_1> is not a placeholder expression, when applied to int it should be treated as a metafunction class?
Yes, this is exactly my point. Another way in which foo<_1> can be forced to not be treated as a ph expression is this:
// no of parms > BOOST_MPL_LIMIT_METAFUNCTION_ARITY template
struct foo { template<typename Q> struct apply{ typedef Q type; }; }; You can try yourself this variation and see that the program really resolves to t1 <- int. But for some reason, the int=0 variation does not do the same, at least in GCC 3.4.4.
Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
PS: I'd greatly appreciate if you could you try the snippet (the int=0 version) with other compilers --my current compiler count is so very limited. Thx!
PPS: In case you're wondering, this is not a purely academic question: I've got a real world scenario where I want to prevent foo<x> from being treated as a ph expression, namely when foo<x> is a metafunction class parameterized by a lambda expression (i.e. a ph expression or metafunction class) x.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hi, I tried the snippet with : gcc 4.1.2 : it doesn't compile because of the assert gcc 4.2.0 : it works icc 9.1 : it works. The second snippet works with all compilers. I already had a discussion about a similar problem on this list, and I finally conclude that not all compilers are using default parameters the same way: In a template template expression, some are expecting the non-type default parameter to be part of the template template expression, and others are not.
""JOAQUIN LOPEZ MU?Z""
According to the MPL reference, a placeholder expression X
must satisfy (among others) the following condition: "All of X's template parameters, including the default ones, are types."
According to that the following should then compile without errors:
#include
#include #include using namespace boost; using namespace boost::mpl;
template
struct foo { template<typename Q> struct apply{ typedef Q type; }; }; typedef apply1
,int>::type t1; BOOST_MPL_ASSERT((is_same
)); int main(){}
However, I've tried with GCC 3.4.4 and the static assertion fails! I'd like to know:
1. Whether I'm right in assuming that the code above should compile without assertion failures.
Yes.
2. What the behavior is for other versions of GCC and compilers: reports most welcome!!
Basically, this is a GCC-specific problem caused by a non-conforming extension that was removed in 4.2.0 (http://gcc.gnu.org/gcc-4.2/changes.html, search for "(undocumented) extension").
3. Whether this is a known problem specific to GCC or, more generally, what the status of this issue is.
It is, and it's not a issue anymore starting with GCC 4.2.
You should be able to work around it for older versions
by providing a specialization of the
'boost::mpl::aux::template_arity' template along the
following lines (untested):
template
----- Mensaje original -----
De: Aleksey Gurtovoy
""JOAQUIN LOPEZ MU?Z""
wrote in message
[...]
1. Whether I'm right in assuming that the code above should compile without assertion failures.
Yes.
2. What the behavior is for other versions of GCC and compilers: reports most welcome!!
Basically, this is a GCC-specific problem caused by a non-conforming extension that was removed in 4.2.0 (http://gcc.gnu.org/gcc-4.2/changes.html, search for "(undocumented) extension").
3. Whether this is a known problem specific to GCC or, more generally, what the status of this issue is.
It is, and it's not a issue anymore starting with GCC 4.2. You should be able to work around it for older versions by providing a specialization of the 'boost::mpl::aux::template_arity' template along the following lines (untested):
template
struct template_arity > : int_<-1> {};
Thank you thank you thank you for the very precise and authoritative information! Best regards, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
participants (5)
-
"JOAQUIN LOPEZ MU?Z"
-
Aleksey Gurtovoy
-
David Abrahams
-
Joaquin M Lopez Munoz
-
Samuel Charron