The Placeholders _1 and _2

Hi All, I am going through Chapter 3 of the MPL book ("A Deeper Look at Metafunctions") and have some questions on the placeholders _1 and _2. They are first introduced in the section 3.1.5 as follows: typename mpl::transform<D1, D2, mpl::minus<_1, _2> >::type I understand from the context that _1 represents D1 and _2 represents D2. From this I understood that _1 will represent the first template argument and _2 will represent the 2nd template argument. This made sense in this context. But later I came across the following in section 3.3: template <class X> struct two_pointers : twice<boost::add_pointer<_1>, X> {}; In this context, it looks like _1 represents X, which is the 2nd template argument. So what exactly _1 and _2 represents? The book doesn't seem to define them. While I haven't completely read the book yet, if it is defined at some other place, it would have been helpful to provide a cross-reference when they are first introduced in chapter 3. Can anybody provide a reference that explains what is a placeholder and what _1 and _2 mean? And what is the maximum number of placeholders? Thank you. Rgds, anna -- Two Party Fraud: Staged Presidential Debates http://missingrainbow.blogspot.com/2008/10/two-party-fraud-staged-presidenti...

AMDG Missing Rainbow wrote:
Hi All,
I am going through Chapter 3 of the MPL book ("A Deeper Look at Metafunctions") and have some questions on the placeholders _1 and _2. They are first introduced in the section 3.1.5 as follows:
typename mpl::transform<D1, D2, mpl::minus<_1, _2> >::type
I understand from the context that _1 represents D1 and _2 represents D2. From this I understood that _1 will represent the first template argument and _2 will represent the 2nd template argument.
Actually transform applies the lambda expression to the elements of the sequences pairwise. mpl::transform<mpl::vector_c<int, 1, 2>, mpl::vector_c<int, 3, 4>, mpl::plus<_1, _2> >::type becomes something equivalent to mpl::vector_c<int, 4, 6> The meaning of _1 and _2 is determined by what transform does with the lambda expression.
This made sense in this context. But later I came across the following in section 3.3:
template <class X> struct two_pointers : twice<boost::add_pointer<_1>, X> {};
_1 means the first argument to the lambda expression. For instance this resolves to template<class F, class T> struct twice : mpl::apply<F, typename mpl::apply<F, X>::type> {}; So two_pointers is equivalent to template<class X> struct two_pointers : boost::add_pointer<typename boost::add_pointer<X>::type> {}; You can see that _1 refers to the first argument to apply. In Christ, Steven Watanabe
participants (2)
-
Missing Rainbow
-
Steven Watanabe