Hi,
I'm stuck at exercise 3-6 of the book. I have to write twice (see below)
as a lambda expression. I don't understand why the same transformation
that works for quasi fails for twice. Any help, please?
#include
Hi,
I'm *partially* answering to myself.
On Thu, 03 Mar 2005 22:54:56 -0200, Bruno Martínez Aguerre
I'm stuck at exercise 3-6 of the book. I have to write twice (see below) as a lambda expression. I don't understand why the same transformation that works for quasi fails for twice. Any help, please?
#include
#include #include
#include #include #include #include #include #include using namespace boost; using namespace boost::mpl; using namespace boost::mpl::placeholders;
template
struct twice : apply ::type > {}; BOOST_MPL_ASSERT(( is_same
,int>::type, int**> )); template
struct quasi : plus ::type > {}; BOOST_MPL_ASSERT(( equal_to
,int_<3> >, int_<7> > ));
This works because quasi inherits from plus that inherits from int_.
template
struct quasi2 : apply >, F, A >::type {};
Here ::type makes quasi2 inherit from int_, too, ...
BOOST_MPL_ASSERT(( equal_to
,int_<3> >, int_<7> > ));
... so this works again.
template
struct twice2 : apply >, F, A >::type {}; BOOST_MPL_ASSERT(( is_same
,int>::type, int**> ));
This has a number of bugs from copying quasi2. Something that works would
be:
template
Bruno Martínez Aguerre writes:
Hi,
Hi Bruno, First of all, sorry for the late reply on this.
I'm *partially* answering to myself.
On Thu, 03 Mar 2005 22:54:56 -0200, Bruno Martínez Aguerre
wrote: I'm stuck at exercise 3-6 of the book. I have to write twice (see below) as a lambda expression. I don't understand why the same transformation that works for quasi fails for twice. Any help, please?
[...]
template
struct twice : apply ::type > {}; BOOST_MPL_ASSERT(( is_same
,int>::type, int**> )); template
struct quasi : plus ::type > {}; BOOST_MPL_ASSERT(( equal_to
,int_<3> >, int_<7> > )); This works because quasi inherits from plus that inherits from int_.
Yep.
template
struct quasi2 : apply >, F, A >::type {}; Here ::type makes quasi2 inherit from int_, too, ...
BOOST_MPL_ASSERT(( equal_to
,int_<3> >, int_<7> > )); ... so this works again.
template
struct twice2 : apply >, F, A >::type {}; BOOST_MPL_ASSERT(( is_same
,int>::type, int**> )); This has a number of bugs from copying quasi2. Something that works would be:
template
struct twice2 : apply< apply1<_1, apply1<_1, _2> >, F, A > {}; BOOST_MPL_ASSERT(( is_same
,int>::type, int**> )); Now, this isn't right yet. If I replace apply1 with apply, it breaks. Could anybody point out why?
That's a subtle pitfall that at very least should be explicitly mentioned in the documentation. I've put it on my TODO list; sorry you've had to struggle with it! In essence, the problem here is that variadic (unnumbered) 'apply' form is never a valid placeholder expression because it always has BOOST_MPL_LIMIT_METAFUNCTION_ARITY + 1 number of template parameters (metafunction to invoke + maximum number of arguments), which is in conflict with the Placeholder Expression concept's requirements -- http://www.boost.org/libs/mpl/doc/refmanual/placeholder-expression.html. When I first realized this, I was thinking about bumping up BOOST_MPL_LIMIT_METAFUNCTION_ARITY internally, so that, in fact, the maximum supported arity of placeholder expressions (but not everything else) would be BOOST_MPL_LIMIT_METAFUNCTION_ARITY + 1, but unfortunately never got to it. I'll consider fixing this for 1.33. Thanks for your feedback, -- Aleksey Gurtovoy MetaCommunications Engineering
Aleksey Gurtovoy wrote:
Bruno Martínez Aguerre writes:
Hi,
Hi Bruno,
First of all, sorry for the late reply on this.
I'm *partially* answering to myself.
On Thu, 03 Mar 2005 22:54:56 -0200, Bruno Martínez Aguerre
wrote: I'm stuck at exercise 3-6 of the book. I have to write twice (see below) as a lambda expression. I don't understand why the same transformation that works for quasi fails for twice. Any help, please?
[...]
template
struct twice : apply ::type > {}; BOOST_MPL_ASSERT(( is_same
,int>::type, int**> )); template
struct quasi : plus ::type > {}; BOOST_MPL_ASSERT(( equal_to
,int_<3> >, int_<7> > )); This works because quasi inherits from plus that inherits from int_.
Yep.
template
struct quasi2 : apply >, F, A >::type {}; Here ::type makes quasi2 inherit from int_, too, ...
BOOST_MPL_ASSERT(( equal_to
,int_<3> >, int_<7> > )); ... so this works again.
template
struct twice2 : apply >, F, A >::type {}; BOOST_MPL_ASSERT(( is_same
,int>::type, int**> )); This has a number of bugs from copying quasi2. Something that works would be:
template
struct twice2 : apply< apply1<_1, apply1<_1, _2> >, F, A > {}; BOOST_MPL_ASSERT(( is_same
,int>::type, int**> )); Now, this isn't right yet. If I replace apply1 with apply, it breaks. Could anybody point out why?
That's a subtle pitfall that at very least should be explicitly mentioned in the documentation. I've put it on my TODO list; sorry you've had to struggle with it!
In essence, the problem here is that variadic (unnumbered) 'apply' form is never a valid placeholder expression because it always has BOOST_MPL_LIMIT_METAFUNCTION_ARITY + 1 number of template parameters (metafunction to invoke + maximum number of arguments), which is in conflict with the Placeholder Expression concept's requirements -- http://www.boost.org/libs/mpl/doc/refmanual/placeholder-expression.html.
When I first realized this, I was thinking about bumping up BOOST_MPL_LIMIT_METAFUNCTION_ARITY internally, so that, in fact, the maximum supported arity of placeholder expressions (but not everything else) would be BOOST_MPL_LIMIT_METAFUNCTION_ARITY + 1, but unfortunately never got to it. I'll consider fixing this for 1.33.
Thanks for your feedback,
Why not have the answers to the exercises in the book on-line so that readers can look at them to further learn the library ?
"Edward Diener"
When I first realized this, I was thinking about bumping up BOOST_MPL_LIMIT_METAFUNCTION_ARITY internally, so that, in fact, the maximum supported arity of placeholder expressions (but not everything else) would be BOOST_MPL_LIMIT_METAFUNCTION_ARITY + 1, but unfortunately never got to it. I'll consider fixing this for 1.33.
Thanks for your feedback,
Why not have the answers to the exercises in the book on-line so that readers can look at them to further learn the library ?
Someone has to write up the answers in a suitable form. That could amount to a lot of work, and we were about at our limit with finishing the book. People have volunteered to do that for other books. Maybe you'd like to take up the challenge? ;-) -- Dave Abrahams Boost Consulting www.boost-consulting.com
David Abrahams wrote:
"Edward Diener"
writes: <snip entire quoted message>
When I first realized this, I was thinking about bumping up BOOST_MPL_LIMIT_METAFUNCTION_ARITY internally, so that, in fact, the maximum supported arity of placeholder expressions (but not everything else) would be BOOST_MPL_LIMIT_METAFUNCTION_ARITY + 1, but unfortunately never got to it. I'll consider fixing this for 1.33.
Thanks for your feedback,
Why not have the answers to the exercises in the book on-line so that readers can look at them to further learn the library ?
Someone has to write up the answers in a suitable form. That could amount to a lot of work, and we were about at our limit with finishing the book. People have volunteered to do that for other books. Maybe you'd like to take up the challenge? ;-)
I am a beginner trying to learn the MPL, and therefore not qualified to offer answers to your exercises. I am surprised that when you wrote the exercises you did not have at least theoretically correct or optimum answers written down somewhere, even in brief form. But being that appears to be the case, hopefully someone else, experienced in MPL, will take up the challenge of providing an answer book, perhaps in on-line form, to your exercises.
"Edward Diener"
David Abrahams wrote:
"Edward Diener"
writes: <snip entire quoted message>
When I first realized this, I was thinking about bumping up BOOST_MPL_LIMIT_METAFUNCTION_ARITY internally, so that, in fact, the maximum supported arity of placeholder expressions (but not everything else) would be BOOST_MPL_LIMIT_METAFUNCTION_ARITY + 1, but unfortunately never got to it. I'll consider fixing this for 1.33.
Thanks for your feedback,
Why not have the answers to the exercises in the book on-line so that readers can look at them to further learn the library ?
Someone has to write up the answers in a suitable form. That could amount to a lot of work, and we were about at our limit with finishing the book. People have volunteered to do that for other books. Maybe you'd like to take up the challenge? ;-)
I am a beginner trying to learn the MPL, and therefore not qualified to offer answers to your exercises.
You could try to answer them as you go through the book; it's surely a good way to learn the material. We'll be happy to try to point you in the right direction if you get stuck.
I am surprised that when you wrote the exercises you did not have at least theoretically correct or optimum answers written down somewhere, even in brief form.
We and our reviewers checked them over to make sure we knew how the exercises might be solved, but we don't have anything written down that's suitable for public presentation.
But being that appears to be the case, hopefully someone else, experienced in MPL, will take up the challenge of providing an answer book, perhaps in on-line form, to your exercises.
It doesn't seem too likely to me; after all those people don't need the answers. Wouldn't it be a much more rewarding experience for someone who was still trying to learn the material? -- Dave Abrahams Boost Consulting www.boost-consulting.com
David,
This is a perfect task for me. I would like to take a crack at it.
I've been around the C++ block quite a few times but am new to MPL.
Regards,
Bruce
-----Original Message-----
From: boost-users-bounces@lists.boost.org
[mailto:boost-users-bounces@lists.boost.org] On Behalf Of David Abrahams
Sent: Monday, March 14, 2005 9:50 AM
To: boost-users@lists.boost.org
Subject: [Boost-users] Re: C++ Template Metaprogramming - Exercise 3-6
"Edward Diener"
David Abrahams wrote:
"Edward Diener"
writes: <snip entire quoted message>
When I first realized this, I was thinking about bumping up BOOST_MPL_LIMIT_METAFUNCTION_ARITY internally, so that, in fact, the maximum supported arity of placeholder expressions (but not everything else) would be BOOST_MPL_LIMIT_METAFUNCTION_ARITY + 1, but unfortunately never got to it. I'll consider fixing this for 1.33.
Thanks for your feedback,
Why not have the answers to the exercises in the book on-line so that readers can look at them to further learn the library ?
Someone has to write up the answers in a suitable form. That could amount to a lot of work, and we were about at our limit with finishing the book. People have volunteered to do that for other books. Maybe you'd like to take up the challenge? ;-)
I am a beginner trying to learn the MPL, and therefore not qualified to offer answers to your exercises.
You could try to answer them as you go through the book; it's surely a good way to learn the material. We'll be happy to try to point you in the right direction if you get stuck.
I am surprised that when you wrote the exercises you did not have at least theoretically correct or optimum answers written down somewhere, even in brief form.
We and our reviewers checked them over to make sure we knew how the exercises might be solved, but we don't have anything written down that's suitable for public presentation.
But being that appears to be the case, hopefully someone else, experienced in MPL, will take up the challenge of providing an answer book, perhaps in on-line form, to your exercises.
It doesn't seem too likely to me; after all those people don't need the answers. Wouldn't it be a much more rewarding experience for someone who was still trying to learn the material? -- Dave Abrahams Boost Consulting www.boost-consulting.com _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Just wondering if others are allowed to play?
I could definitely use the practice to get my MPL skills up. I can
even provide a wiki or some such if there are issues with using the
boost wiki for this.
Ciao,
ajh
On Mon, 14 Mar 2005 10:52:20 -0500, Bruce Trask
David,
This is a perfect task for me. I would like to take a crack at it. I've been around the C++ block quite a few times but am new to MPL.
Regards, Bruce
--
#include
AJ Harrington
Just wondering if others are allowed to play?
As far as I'm concerned, yes.
I could definitely use the practice to get my MPL skills up. I can even provide a wiki or some such if there are issues with using the boost wiki for this.
The Boost Wiki is the perfect place for it.
On Mon, 14 Mar 2005 10:52:20 -0500, Bruce Trask
wrote: David,
This is a perfect task for me. I would like to take a crack at it. I've been around the C++ block quite a few times but am new to MPL.
Regards, Bruce
-- #include
using std::disclaimer; use Std::Disclaimer; <!ENTITY standard-disclaimer SYSTEM "http://127.0.0.1/StdDisclaimer.xml">
-- Dave Abrahams Boost Consulting www.boost-consulting.com
On Mon, 2005-03-14 at 09:11 -0800, AJ Harrington wrote:
Just wondering if others are allowed to play?
Sure! Call me crazy but I think I am going to need help.
I could definitely use the practice to get my MPL skills up.
Me too.
I can even provide a wiki or some such if there are issues with using the boost wiki for this.
Great. Regards, Bruce
Ciao,
ajh
On Mon, 14 Mar 2005 10:52:20 -0500, Bruce Trask
wrote: David,
This is a perfect task for me. I would like to take a crack at it. I've been around the C++ block quite a few times but am new to MPL.
Regards, Bruce
Count me in on this too. I've been working through the problems and have about a dozen answers. I'll try to commit them to the wiki after the software developers conference. Chris Bruce Trask wrote:
On Mon, 2005-03-14 at 09:11 -0800, AJ Harrington wrote:
Just wondering if others are allowed to play?
Sure! Call me crazy but I think I am going to need help.
I could definitely use the practice to get my MPL skills up.
Me too.
I can even provide a wiki or some such if there are issues with using the boost wiki for this.
Great.
Regards, Bruce
Ciao,
ajh
On Mon, 14 Mar 2005 10:52:20 -0500, Bruce Trask
wrote: David,
This is a perfect task for me. I would like to take a crack at it. I've been around the C++ block quite a few times but am new to MPL.
Regards, Bruce
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (7)
-
AJ Harrington
-
Aleksey Gurtovoy
-
Bruce Trask
-
Bruno Martínez Aguerre
-
Chris Goller
-
David Abrahams
-
Edward Diener