Boost logo

Boost :

From: Arkadiy Vertleyb (vertleyb_at_[hidden])
Date: 2004-12-02 09:55:08

"David Abrahams" <dave_at_[hidden]> wrote

> Peder Holt wrote:
> > given a metafunction is_iterator<> there may be a way around this
> Problem is, it's impossible to write that metafunction.

Well, it's not possible in general case, but for the purpose of typeof, a
rough approximation may be enough. We can just assume that, if the type was
not caught by all the specializations (generated by registration), then it
*might be* one of the standard iterators. We can use SFINAE, examining
value_type, distance_type, etc., to increase the probability of that

The value_type then may be extracted, and using it, all the thing may be
matched against pre-defined specializations for standard iterators, like:

// call
traits<It::value_type, It>::....

// specialization
template<class T> class traits<T, vector<T>::iterator>

Now T can be deduced (at least by VC7.1). If our guess was wrong, and this
is not a standard iterator after all, it will fail at this stage.

The problem with this approach is that, also it's [usually] possible to
extract value_type from the iterator, it's not true for allocators,
predicates, etc., and so can work only for containers with defaults.

Note that the problem is unfortunate mostly because of standard iterators.
In general case, iterators can be developed as stand-alone templates, and
typedef in the container can be used. These kind of iterators can be just
registered as any other template.


Boost list run by bdawes at, gregod at, cpdaniel at, john at