Re: [Boost-users] [mpl] Iterator Concept Checking? SOLVED + Recommendation.

On Sun, Oct 31, 2010 at 6:16 PM, Stirling Westrup
I have solved the problem I was working on, but as I'm not completely
happy with my solution, I thought I'd post it here and make a
recommendation for a small change to MPL that would have simplified my
work.
I discovered while reading about the iterator_category metafunction
that the iterator tags had ascending values. (
http://www.boost.org/doc/libs/1_44_0/libs/mpl/doc/refmanual/iterator-categor...
). This is only documented there, and not in the description of the
individual iterator categories. In fact, the individual iterator
categories are completely misleading as they state that there is a
member named 'category' that is convertible to the type of the tag.
Since a random iterator is a refinement of a forward iterator and
therefor has at least the same set of requirements, it would imply
that:
BOOST_MPL_ASSERT
(( is_convertibleRandomIterator::category,forward_iterator_tag))
should succeed, and it does NOT.
It would seem that one should use iterator_category to determine if
something is an iterator or not, but its only actually defined when
its type is an iterator, so that doesn't really work. I ended up
writing my own version that was defined for all types, like this:
struct non_iterator_tag : mpl::int_

At Tue, 2 Nov 2010 21:06:25 -0400, Stirling Westrup wrote:
^^^^^^^^^^
member named 'category' that is convertible to the type of the tag.
Who states? Where? Oh, after searching... you mean, e.g., http://www.boost.org/doc/libs/1_44_0/libs/mpl/doc/refmanual/bidirectional-it... right?
What implies that? OK, found it...
It would seem that one should use iterator_category to determine if something is an iterator or not,
That wouldn't work for STL iterators; can you explain why you would expect it to work here?
I'm sorry, I don't understand what you're trying to say about deprecation. Deprecation is a human activity; iterator_category<> can't deprecate anything.
Well, we have a problem, in that a BidirectionalIterator is-not-a ForwardIterator by MPL's requirements, even though the documentation claims it is a refinement. So MPL's concepts are just broken, and we need to fix that. Aleksey? -- Dave Abrahams BoostPro Computing http://www.boostpro.com

On Wed, Nov 3, 2010 at 10:02 PM, David Abrahams
Correct.
Well, as in the code I included in the original post of this thread, one usually wants to see what iterator concept is being modeled by a particular type, to ensure that the code that makes use of the type can rely on certain properties. Checking to see that something is an iterator and then checking to see if it is a particular model of an iterator seems to be a waste, as the only use of the first check is to see if the second would succeed. Why not just guarantee that the second would succeed? Its not hard to do, but it should be provided as part of the standard MPL, not as an add-on, as I did.
Sorry if I was unclear. I meant that use of Iterator::category would likely be deprecated in favour of using iterator_category<Iterator>::type, just as Iterator::deref and Iterator::next have been deprecated in favour of deref<Iterator>::type and next<Iterator>::type, and for the same reason. The extra level of indirection allows for greater flexibility in what sorts of types can be MPL iterators.
I should mention, at this point, that this is completely analogous to how the sequence_tag<X> metafunction works, as it returns a valid sequence tag for any sequence type, and returns non_sequence_tag for any non-sequence. This is extremely useful, and I just want something that works exactly the same for iterators.
Yup. -- Stirling Westrup Programmer, Entrepreneur. https://www.linkedin.com/e/fpf/77228 http://www.linkedin.com/in/swestrup http://technaut.livejournal.com

On Tue, 02 Nov 2010 20:06:25 -0500, Stirling Westrup
I agree, the docs are currently misleading/incorrect; please see below, though.
I considered this at some point, but in the end failed to come up with a use case for an iterator type that _has_ to be adopted "as is" and decided not to bother. Plus checking for the 'category' member is a little to broad of a test, IMHO.
We can either fix the docs or fix the code. I'm actually inclined to fix the code. There are two reasons why I deviated from the standard iterator tags' relationship: 1. I wanted this to work: typedef typename min< typename iterator_category<iter1>::type , typename iterator_category<iter2>::type >::type category; 2. I *thought* I had no use case for keeping the inheritance, and preserving it while also supporting #1 seemed like unnecessary hassle. Now that you pointed out that by removing it I both broke the docs *and* violated at least one person's expectations, "the hassle" seems more like a win-win solution to me: the docs would become correct again, you (and the rest of the users) would get intuitively expected, standard-like relationship between tags and ability to test them with 'is_convertible', and I'd still get to keep #1. Thoughts? -- Aleksey Gurtovoy MetaCommunications Engineering
participants (3)
-
Aleksey Gurtovoy
-
David Abrahams
-
Stirling Westrup