0
votes

I'm reading David Abrahams's C++ Template Metaprogramming, on ch 5.6 Sequence Equality he says:

It's important, particularly when handling computed results, not to fall into the trap of relying on sequence type identity. For example, you should not expect the following assertion to pass:

BOOST_STATIC_ASSERT((      // error
  boost::is_same<
      mpl::pop_back<mpl::vector<int, short> >::type
    , mpl::vector<int>
  >::value
)); 

For most purposes, the two types being compared above will act the same, and most of the time you'll never notice a difference. That said, the result of using mpl::pop_back on a specialization of mpl::vector will not be another specialization of mpl::vector!

As you saw in our exploration of dimensional analysis in Chapter 3, a function template that can only be called with two identical types is likely not to work as expected if those types are sequences. The same goes for a class template partial specialization that matches only when two type arguments are identical.

The correct way to check for sequence equality is always to use the equal algorithm, as follows:

BOOST_STATIC_ASSERT((        // OK
  mpl::equal<
      mpl::pop_back<mpl::vector<int, short> >::type
    , mpl::vector<int>
  >::value
));

I don't understand here: "That said, the result of using mpl::pop_back on a specialization of mpl::vector will not be another specialization of mpl::vector", then what is the result of mpl::popback here?

Boost manual on pop_back says the Return type is "Back Extensible Sequence", isn't mpl::vector a back extensible sequence?

1

1 Answers

0
votes

It will be a constructed sequence type of some kind, You can look at the pop_back_impl for vector in