Question about traversing mpl vectors

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? typedef mpl::next<element2>::type element3; // " typedef mpl::next<element3>::type element4; // " ================================================== Will boost let me iterate past the 'end' of an mpl::vector? Am I supposed to take care of bounds checking? Thanks, --Steve Stephen Gross Case Western School of Medicine Cleveland, OH "By Grabthar's hammer, by the sons of Worvan, you shall be avenged." - Dr. Lazarus

"Stephen Gross" <sgross@darwin.epbi.cwru.edu> 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
participants (2)
-
David Abrahams
-
Stephen Gross