
Hi Stirling, 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.
The MPL library doesn't seem to have is_XXX_iterator<T> checks, and I have run into some difficulties in determining how to write them. The MPL documents state that a random_access_iterator is a 'refinement' of a bidirectional_iterator which is a 'refinement' of a forward_iterator, but its not clear what refinement means in this context.
http://www.generic-programming.org/about/intro/concepts.php#refinement
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.
This does not appear to be the case, so the obvious test for an iterator (checking that the class contains a member named 'category' that is a type derived from the iterator tag of the least acceptable iterator) will not work.
I am sure I could cobble together something that would work by examining the internals of the library, but I would far rather have some guidance on the correct way to see if an iterator matches a given iterator model, within the API of the library.
Does anyone have any suggestions?
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? 1. Do you understand the requirements of that concept? 2. Do you understand how to test if those requirements are met? -- Dave Abrahams BoostPro Computing http://www.boostpro.com