Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2005-08-04 19:58:06


"Stephen Gross" <sgross_at_[hidden]> writes:

> Let's say I've got some mpl::vector. If I grab a begin iterator on it, and
> increment that iterator past the elements in the vector, what happens? For
> instance:
>
> ==================================================
> using boost;
> typedef mpl::vector<int, char> t;
> typedef mpl::begin<t>::type element0; // Should deref to 'int'
> typedef mpl::next<element0>::type element1; // Should deref to 'char'
> typedef mpl::next<element1>::type element2; // What happens?

Undefined behavior. If you're lucky, a compilation error.

> typedef mpl::next<element2>::type element3; // "
> typedef mpl::next<element3>::type element4; // "
> ==================================================
>
> Will boost let me iterate past the 'end' of an mpl::vector?

There are no guarantees in that regard.

> Am I supposed to take care of bounds checking?

If bounds need to be checked, you're supposed to take care of it. I
can't say as I've ever had to do bounds checking in MPL code, though.

HTH,

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net