Boost logo

Boost Users :

Subject: Re: [Boost-users] [mpl] Iterator Concept Checking?
From: Stirling Westrup (swestrup_at_[hidden])
Date: 2010-10-31 18:16:21


On Sat, Oct 30, 2010 at 8:57 PM, David Abrahams <dave_at_[hidden]> wrote:
>
> At Sat, 30 Oct 2010 17:55:35 -0400,
> Stirling Westrup wrote:
>>
>> I am writing some algorithms to operate on MPL sequences, and I would
>> like to use some form of concept checking to ensure that the types
>> passed in that are supposed to be iterators are, in fact, iterators.
>>

> http://www.generic-programming.org/about/intro/concepts.php#refinement

Thanks. That answers one of my questions then.

>> I initially assumed that this meant that a random_access_iterator_tag
>> was derived from a bidirectional_iterator_tag which was derived from a
>> forward_iterator_tag.
>
> That's a useful trick if you're calling runtime functions, but it
> wouldn't be useful for MPL as written.

I'm not so sure of that, but I'm willing to be convinced otherwise.

> I'm not sure exactly how to help, because I can't quite tell where
> you're stuck, so let me ask a few questions:

> 0. Which iterator concept do you want to check for?

All of them. Right now I need to test for forward iterators but I have
some algorithms planned that are likely to want random access
iterators. I figure if I have to write one of the concept checks, I
may as well write all three.

> 1. Do you understand the requirements of that concept?

This is the big kicker for me. As far as I can tell from the
documents, there are only three requirements, and two (for deref and
next) don't apply to past-the-end iterators.

Since I need

  BOOST_MPL_ASSERT(( is_forward_iterator<end<Sequence>::type> ))

to succeed, I cannot test for deref<T> or next<T> being valid, as
neither is required for past-the-end iterators. That leaves me with
testing that there is a member called category that is convertible to
an iterator tag that is a refinement of forward_iterator. This would
seem to require me to have an explicit encoding of the relationships
between the iterator tags as they do not have an intrinsic
relationship that I can test. At least, this is how it seems to me.
Have I missed something?

> 2. Do you understand how to test if those requirements are met?

Well, I have never actually had to write a concept check before, as
I've always been able to find an existing one to meet my needs, but I
think I have a decent grasp of the theory.

-- 
Stirling Westrup
Programmer, Entrepreneur.
https://www.linkedin.com/e/fpf/77228
http://www.linkedin.com/in/swestrup
http://technaut.livejournal.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