Boost logo

Boost :

From: Arkadiy Vertleyb (vertleyb_at_[hidden])
Date: 2006-05-23 14:54:53


"Eric Niebler" <eric_at_[hidden]> wrote

> Even if you were willing to accept that, in order to use this macro, you
> may have to register types with BOOST_TYPEOF (an interface I'm not
> overly fond of), there are still problems. Registering types for
> iterators is notoriously difficult. How would you write the BOOST_TYPEOF
> registrations for the std::vector iterators, for instance, considering
> that they could very well be defined as:
>
> namespace std {
> template<class T, class Al>
> struct vector {
> struct iterator {
> //...
> };
> };
> }
>
> // register std::vector<T,Al>::iterator
> BOOST_TYPEOF_REGISTER_TYPE(?????)
>
> Has anyone solved this problem?

No. But you can write something like following:

for (BOOST_TYPEOF(v)::iterator it = v.begin(); ...

Of course, this introduces another issue -- the need to choose between
"iterator" and "const_iterator" based on the constness of the vector. But
this should be possible to do...

The registration problem is still there... One thing that could be done
(and was discussed before in relation to result_of) is to enable
compile-time detection of whether typeof is possible for a given expression
(meaning native typeof is used or all needed types are registered) without
causing compiler error. In theory then, you could use it to optimize your
FOREACH provided typeof is available.

Regards,
Arkadiy
Regards,
Arkadiy


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk