
"Jonathan Turkanis" <technews@kangaroologic.com> wrote in message news:cgapf9$tgn$1@sea.gmane.org...
"Alex Chovanec" <achovane@engin.umich.edu> wrote in message news:cganiq$q27$1@sea.gmane.org...
I've attached a naively modified version of David Abraham's is_incrementable as a first attempt at is_dereferenceable. There may be all sorts of subtle issues I haven't though of.
Ok I'll check it out. Maybe it's more robust than the SFINAE approach to recognizing overloaded operators which I'm using right now.
(and more generally, whether or not it's an iterator).
Why? When you write a template, you always have some idea of the range of types for which the template should be instantiated. It's rarely instantiable for all types. Given this, all you need is a way to separate iterators from the other candidate template arguments.
Ok, so I have a class Ptr_Wrapper that is a wrapper around a pointer to an object of arbitrary type, and it has a template constructor which accepts any kind of iterator. The constructor initializes the pointer member with the address of the object that the iterator refers to. Now, I don't want is_convertible<T, Ptr_Wrapper> to be true for any type T, so I want to use the enable_if library to eliminate specializations of the template constructor where the type passed in is not a Readable Lvalue iterator with the correct pointer type. But again, I can't just use is_readable_iterator<T> and is_lvalue_iterator<T>, because either one will cause a compile error if T is not an iterator. I don't want there to be a compile error in this case, because Ptr_Wrapper has another constructor which accepts a reference to an object an initializes the pointer member from that. I want this constructor to be chosen if a reference is passed instead of an iterator. Thus, in the template metaprogram that I use to decide whether or not to include a particular template specialization of the constructor in the set of candidate functions, I need to check that T is some kind of iterator before applying is_readable_iterator<T> and is_lvalue_iterator<T>. Otherwise, I may get an unwanted compile error. Thanks, Alex